diff --git a/site/data/sidebar.yml b/site/data/sidebar.yml index b3036aa12068..cfb3e1764994 100644 --- a/site/data/sidebar.yml +++ b/site/data/sidebar.yml @@ -13,6 +13,8 @@ - title: JavaScript - title: Accessibility # - title: Community + - title: Examples + href: examples/ - title: Guides section: Guides diff --git a/site/src/components/DocsSidebar.astro b/site/src/components/DocsSidebar.astro index 4da2d840b4c5..8cb4751fccda 100644 --- a/site/src/components/DocsSidebar.astro +++ b/site/src/components/DocsSidebar.astro @@ -6,33 +6,66 @@ import { getSlug } from '@libs/utils' import NewBadge from '@components/NewBadge.astro' const sidebar = getData('sidebar') + +// Derive active section from the current slug +const { slug } = Astro.params +const currentDir = (slug as string)?.split('/')[0] ?? '' +const activeSection = sidebar.find((g) => getSlug(g.title) === currentDir)?.section + +// Only show groups that belong to the active section; fall back to all groups +const visibleGroups = activeSection ? sidebar.filter((g) => g.section === activeSection) : sidebar + +// Skip group headings when there's only one group in the section +const skipGroupHeading = visibleGroups.filter((g) => g.pages).length === 1 ---