diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-14 02:41:24 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-14 02:44:46 +0300 |
| commit | ca7ae086e8d6e80f6efc969d541b390328a6d143 (patch) | |
| tree | 85605d0551af1dd2a25dce633fd83a06281598d7 /website/src/docs-path.ts | |
| parent | 2e5da968ea3fb7105c56f7674caf822de41ec176 (diff) | |
fix(website): scope docs search by locale and channel
Diffstat (limited to 'website/src/docs-path.ts')
| -rw-r--r-- | website/src/docs-path.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/website/src/docs-path.ts b/website/src/docs-path.ts new file mode 100644 index 00000000..be022a4b --- /dev/null +++ b/website/src/docs-path.ts @@ -0,0 +1,20 @@ +const docsLocales = new Set(['ja', 'zh-cn']); + +export function docsChannel(pathname: string) { + return /^\/(?:ja\/|zh-cn\/)?docs\/preview(?:\/|$)/.test(pathname) ? 'preview' : 'stable'; +} + +export function docsPath({ entry }: { entry: string }) { + const slug = entry.replace(/\.(md|mdx|markdown|mdown|mkdn|mkd|mdwn)$/i, ''); + const normalized = slug.replace(/\/index$/, ''); + const segments = normalized.split('/'); + const localeIndex = segments[0] === 'preview' ? 1 : 0; + const locale = segments[localeIndex]; + + if (locale && docsLocales.has(locale)) { + segments.splice(localeIndex, 1); + return `${locale}/docs${segments.length > 0 ? `/${segments.join('/')}` : ''}`; + } + + return normalized === 'index' ? 'docs' : `docs/${normalized}`; +} |
