diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-22 14:58:26 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-22 14:59:09 +0300 |
| commit | c234f221f9be698bc0501c60459e1ae8e67df6c3 (patch) | |
| tree | 944b4dec10fada8d93456dc5a85e6bfdb36a8b8b /website/src/components/Sidebar.astro | |
| parent | ef85fa0c7ebb48bb59fe7593af5a67f3e02ff3d4 (diff) | |
feat(docs): publish versioned release documentation
Diffstat (limited to 'website/src/components/Sidebar.astro')
| -rw-r--r-- | website/src/components/Sidebar.astro | 67 |
1 files changed, 22 insertions, 45 deletions
diff --git a/website/src/components/Sidebar.astro b/website/src/components/Sidebar.astro index 8ded83bb..08d31f79 100644 --- a/website/src/components/Sidebar.astro +++ b/website/src/components/Sidebar.astro @@ -2,62 +2,39 @@ import MobileMenuFooter from 'virtual:starlight/components/MobileMenuFooter'; import SidebarPersister from '@astrojs/starlight/components/SidebarPersister.astro'; import SidebarSublist from '@astrojs/starlight/components/SidebarSublist.astro'; +import versions from '../data/docs-versions.json'; +import { docsRoute, docsTargetHref } from '../docs-path'; const { sidebar } = Astro.locals.starlightRoute; const pathname = Astro.url.pathname; -const isPreview = pathname === '/docs/preview/' || pathname.startsWith('/docs/preview/'); -const channelSidebar = isPreview ? addPreviewOnlyItems(rewriteSidebar(sidebar)) : sidebar; +const route = docsRoute(pathname); +const scopedSidebar = route.target === 'stable' ? sidebar : rewriteSidebar(sidebar); -function addPreviewOnlyItems(entries) { - return entries.map((entry) => { - if (entry.type !== 'group' || entry.label !== 'Start here') return entry; - - const windowsBeta = { - type: 'link', - label: 'Windows beta', - href: '/docs/preview/windows-beta/', - badge: undefined, - isCurrent: samePath('/docs/preview/windows-beta/', pathname), - attrs: {}, - }; - const nextEntries = []; - for (const child of entry.entries) { - nextEntries.push(child); - if (child.type === 'link' && child.label === 'Install') { - nextEntries.push(windowsBeta); +function rewriteSidebar(entries) { + return entries.flatMap((entry) => { + if (entry.type === 'link') { + const linkRoute = docsRoute(entry.href); + if (!linkRoute.isDocs) return [entry]; + if (linkRoute.target !== 'stable') { + return linkRoute.target === route.target + ? [{ ...entry, isCurrent: samePath(entry.href, pathname) }] + : []; } - } - return { - ...entry, - entries: nextEntries, - }; - }); -} + const localeKey = route.locale ?? 'root'; + const availablePages = versions.scopes[route.target]?.locales[localeKey] ?? []; + if (!availablePages.includes(linkRoute.page)) return []; -function rewriteSidebar(entries) { - return entries.map((entry) => { - if (entry.type === 'link') { - const href = previewHref(entry.href); - return { - ...entry, - href, - isCurrent: samePath(href, pathname), - }; + const href = docsTargetHref({ ...linkRoute, locale: route.locale }, route.target, versions.scopes); + return [{ ...entry, href, isCurrent: samePath(href, pathname) }]; } + const rewrittenEntries = rewriteSidebar(entry.entries); - return { - ...entry, - entries: rewrittenEntries, - }; + if (rewrittenEntries.length === 0) return []; + return [{ ...entry, entries: rewrittenEntries }]; }); } -function previewHref(href) { - if (!href.startsWith('/docs/') || href.startsWith('/docs/preview/')) return href; - return href === '/docs/' ? '/docs/preview/' : href.replace(/^\/docs\//, '/docs/preview/'); -} - function samePath(left, right) { return stripTrailingSlash(left) === stripTrailingSlash(right); } @@ -68,7 +45,7 @@ function stripTrailingSlash(path) { --- <SidebarPersister> - <SidebarSublist sublist={channelSidebar} /> + <SidebarSublist sublist={scopedSidebar} /> </SidebarPersister> <div class="md:sl-hidden"> |
