From f2bf7077ff7d8f145f1cb65cf234c40f3d3b8705 Mon Sep 17 00:00:00 2001 From: DivisionByZero Date: Mon, 29 Apr 2024 09:41:24 +0200 Subject: [PATCH] docs(website): show same sidebar on all pages (#2855) --- docs/.vitepress/config.ts | 133 ++++++++++++++------------------------ 1 file changed, 49 insertions(+), 84 deletions(-) diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index e92efc8e073..3bb9c9355ba 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -14,25 +14,44 @@ const description = 'Generate massive amounts of fake (but reasonable) data for testing and development.'; const image = 'https://fakerjs.dev/social-image.png'; -function extendSideNav(current: SidebarItem): SidebarItem[] { +function getSideBarWithExpandedEntry(entryToExpand: string): SidebarItem[] { const links: SidebarItem[] = [ { text: 'Guide', items: [ { - text: 'Usage Guide', + text: 'Getting Started', link: '/guide/', }, + { + text: 'Usage', + link: '/guide/usage', + }, + { + text: 'Localization', + link: '/guide/localization', + }, + { + text: 'Frameworks', + link: '/guide/frameworks', + }, + { + text: 'Randomizer', + link: '/guide/randomizer', + }, + { + text: 'Unique Values', + link: '/guide/unique', + }, + { + text: 'Upgrading to v9', + link: '/guide/upgrading', + }, ], }, { text: 'API', - items: [ - { - text: 'API Reference', - link: '/api/', - }, - ], + items: apiPages, }, { text: 'About', @@ -40,10 +59,26 @@ function extendSideNav(current: SidebarItem): SidebarItem[] { { text: 'Announcements', link: '/about/announcements', + items: [ + { text: '2022-09-08', link: '/about/announcements/2022-09-08' }, + { text: '2022-01-14', link: '/about/announcements/2022-01-14' }, + ], }, { text: 'Roadmap', link: '/about/roadmap/', + items: [ + { + text: 'v9 - Tree-Shakeable Module-Functions', + link: '/about/roadmap/v9', + }, + { text: 'v8 - Make Faker Handier', link: '/about/roadmap/v8' }, + { + text: 'v7 - Cleanup & Improvements', + link: '/about/roadmap/v7', + }, + { text: 'v6 - Continue Faker', link: '/about/roadmap/v6' }, + ], }, { text: 'Team', @@ -56,7 +91,9 @@ function extendSideNav(current: SidebarItem): SidebarItem[] { ], }, ]; - links[links.findIndex((group) => group.text === current.text)] = current; + for (const entry of links) { + entry.collapsed = entry.text !== entryToExpand; + } return links; } @@ -197,81 +234,9 @@ const config: UserConfig = { ], sidebar: { - '/guide/': extendSideNav({ - text: 'Guide', - items: [ - { - text: 'Getting Started', - link: '/guide/', - }, - { - text: 'Usage', - link: '/guide/usage', - }, - { - text: 'Localization', - link: '/guide/localization', - }, - { - text: 'Frameworks', - link: '/guide/frameworks', - }, - { - text: 'Randomizer', - link: '/guide/randomizer', - }, - { - text: 'Unique Values', - link: '/guide/unique', - }, - { - text: 'Upgrading to v9', - link: '/guide/upgrading', - }, - ], - }), - '/api/': extendSideNav({ - text: 'API', - items: apiPages, - }), - - '/about/': extendSideNav({ - text: 'About', - items: [ - { - text: 'Announcements', - link: '/about/announcements', - items: [ - { text: '2022-09-08', link: '/about/announcements/2022-09-08' }, - { text: '2022-01-14', link: '/about/announcements/2022-01-14' }, - ], - }, - { - text: 'Roadmap', - link: '/about/roadmap/', - items: [ - { - text: 'v9 - Tree-Shakeable Module-Functions', - link: '/about/roadmap/v9', - }, - { text: 'v8 - Make Faker Handier', link: '/about/roadmap/v8' }, - { - text: 'v7 - Cleanup & Improvements', - link: '/about/roadmap/v7', - }, - { text: 'v6 - Continue Faker', link: '/about/roadmap/v6' }, - ], - }, - { - text: 'Team', - link: '/about/team', - }, - { - text: 'Contributing', - link: '/about/contributing', - }, - ], - }), + '/guide/': getSideBarWithExpandedEntry('Guide'), + '/api/': getSideBarWithExpandedEntry('API'), + '/about/': getSideBarWithExpandedEntry('About'), }, },