]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
docs: better slugify
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 3 Aug 2023 08:32:04 +0000 (10:32 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 3 Aug 2023 08:32:04 +0000 (10:32 +0200)
packages/docs/.vitepress/config/shared.ts

index cf84a4f605d94ee72a350df467df8358a75763b5..80849394520297c71d44f4de942e1372d730a934 100644 (file)
@@ -10,6 +10,25 @@ if (process.env.NETLIFY) {
   console.log('Netlify build', process.env.CONTEXT)
 }
 
+const rControl = /[\u0000-\u001f]/g
+const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g
+const rCombining = /[\u0300-\u036F]/g
+
+/**
+ * Default slugification function
+ */
+export const slugify = (str: string): string =>
+  str
+    .normalize('NFKD')
+    // Remove accents
+    .replace(rCombining, '')
+    // Remove control characters
+    .replace(rControl, '')
+    // Replace special characters
+    .replace(rSpecial, '-')
+    // ensure it doesn't start with a number
+    .replace(/^(\d)/, '_$1')
+
 const productionHead: HeadConfig[] = [
   [
     'script',
@@ -37,7 +56,7 @@ export const sharedConfig = defineConfig({
     },
 
     anchor: {
-      slugify: s => s.replace(/\s/g, '-'),
+      slugify,
     },
   },