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

index 0127721bc8363cdaec1acf5d0d2b8b524ab3cd71..53c162db7b868e1615da5842a15651d66462f920 100644 (file)
@@ -19,6 +19,25 @@ const productionHead: HeadConfig[] = [
   ],
 ]
 
+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')
+
 export const sharedConfig = defineConfig({
   title: 'Pinia',
   appearance: 'dark',
@@ -33,6 +52,10 @@ export const sharedConfig = defineConfig({
       leftDelimiter: '%{',
       rightDelimiter: '}%',
     },
+
+    anchor: {
+      slugify,
+    },
   },
 
   head: [