diff --git a/.vitepress/config.js b/.vitepress/config.js index d8e16645a..298b5b49e 100644 --- a/.vitepress/config.js +++ b/.vitepress/config.js @@ -8,6 +8,7 @@ import { fileURLToPath } from 'node:url' import { defineConfig } from 'vitepress' import languages from './languages' import playground from './lib/cds-playground/index.js' +import { slugify } from './lib/slugify.ts' import { Menu } from './menu.js' const __dirname = dirname(fileURLToPath(import.meta.url)) @@ -46,10 +47,7 @@ const config = defineConfig({ }, anchor: { // VS Code-compatible GitHub-style slugifier (mirrors markdown-language-features/src/slugify.ts) - slugify: (str) => str - .trim().toLowerCase() - .replace(/[^\p{L}\p{N}\p{M}\s_-]/gu, '') - .replace(/\s/g, '-'), + slugify, }, container: { // Doesn't seem to work yet infoLabel: 'Info', diff --git a/.vitepress/lib/slugify.ts b/.vitepress/lib/slugify.ts new file mode 100644 index 000000000..9ab18a23c --- /dev/null +++ b/.vitepress/lib/slugify.ts @@ -0,0 +1,8 @@ +// VS Code-compatible GitHub-style slugifier (mirrors markdown-language-features/src/slugify.ts). +// Used as VitePress' markdown anchor slugifier, and reused to derive heading anchors elsewhere (e.g. llms-full.txt). +export function slugify(str: string): string { + return str + .trim().toLowerCase() + .replace(/[^\p{L}\p{N}\p{M}\s_-]/gu, '') + .replace(/\s/g, '-') +}