Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(website): show same sidebar on all pages #2855

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 49 additions & 84 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,71 @@ 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',
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',
Expand All @@ -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;
}

Expand Down Expand Up @@ -197,81 +234,9 @@ const config: UserConfig<DefaultTheme.Config> = {
],

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'),
},
},

Expand Down