Skip to content

Commit d18c650

Browse files
committed
docs: fix slugify for api
1 parent 0ebc245 commit d18c650

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

docs/.vitepress/config.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@ import {
1111
releases,
1212
} from './meta'
1313

14+
const rControl = /[\u0000-\u001f]/g
15+
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g
16+
const rCombining = /[\u0300-\u036F]/g
17+
18+
/**
19+
* Default slugification function
20+
*/
21+
export const slugify = (str: string): string =>
22+
str
23+
.normalize('NFKD')
24+
// Remove accents
25+
.replace(rCombining, '')
26+
// Remove control characters
27+
.replace(rControl, '')
28+
// Replace special characters
29+
.replace(rSpecial, '-')
30+
// ensure it doesn't start with a number
31+
.replace(/^(\d)/, '_$1')
32+
1433
export default defineConfig({
1534
lang: 'en-US',
1635
title: headTitle,
@@ -28,7 +47,7 @@ export default defineConfig({
2847
},
2948

3049
anchor: {
31-
slugify: (s: string) => s.replace(/\s+/g, '-'),
50+
slugify,
3251
},
3352
},
3453

0 commit comments

Comments
 (0)