diff options
author | HiDeoo | 2023-08-10 23:15:39 +0200 |
---|---|---|
committer | GitHub | 2023-08-10 23:15:39 +0200 |
commit | 35cd82e7f8622772a5155add99ad8baf61ae08a1 (patch) | |
tree | cdf6fef5fe26474bbe228c926c56f3efcdd6358e | |
parent | 14df4eda96eb2efc01fed4d991e44f66656f8b17 (diff) | |
download | IT.starlight-35cd82e7f8622772a5155add99ad8baf61ae08a1.tar.gz IT.starlight-35cd82e7f8622772a5155add99ad8baf61ae08a1.tar.bz2 IT.starlight-35cd82e7f8622772a5155add99ad8baf61ae08a1.zip |
Respect `hidden` sidebar frontmatter when sidebar config is unset (#489)
-rw-r--r-- | .changeset/three-bobcats-lay.md | 5 | ||||
-rw-r--r-- | packages/starlight/__tests__/basics/navigation.test.ts | 1 | ||||
-rw-r--r-- | packages/starlight/utils/navigation.ts | 35 |
3 files changed, 24 insertions, 17 deletions
diff --git a/.changeset/three-bobcats-lay.md b/.changeset/three-bobcats-lay.md new file mode 100644 index 00000000..65facc64 --- /dev/null +++ b/.changeset/three-bobcats-lay.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Respect `hidden` sidebar frontmatter property when no sidebar configuration is provided diff --git a/packages/starlight/__tests__/basics/navigation.test.ts b/packages/starlight/__tests__/basics/navigation.test.ts index f4d0dbb1..29da09df 100644 --- a/packages/starlight/__tests__/basics/navigation.test.ts +++ b/packages/starlight/__tests__/basics/navigation.test.ts @@ -7,6 +7,7 @@ vi.mock('astro:content', async () => ['index.mdx', { title: 'Home Page' }], ['environmental-impact.md', { title: 'Eco-friendly docs' }], ['guides/authoring-content.md', { title: 'Authoring Markdown' }], + ['reference/frontmatter.md', { title: 'Frontmatter Reference', sidebar: { hidden: true } }], ['guides/components.mdx', { title: 'Components' }], ], }) diff --git a/packages/starlight/utils/navigation.ts b/packages/starlight/utils/navigation.ts index 816c5e79..d12c6914 100644 --- a/packages/starlight/utils/navigation.ts +++ b/packages/starlight/utils/navigation.ts @@ -83,11 +83,9 @@ function groupFromAutogenerateConfig( const dirDocs = routes.filter( (doc) => // Match against `foo.md` or `foo/index.md`. - (stripExtension(doc.id) === localeDir || - // Match against `foo/anything/else.md`. - doc.id.startsWith(localeDir + '/')) && - // Remove any entries that should be hidden - !doc.entry.data.sidebar.hidden + stripExtension(doc.id) === localeDir || + // Match against `foo/anything/else.md`. + doc.id.startsWith(localeDir + '/') ); const tree = treeify(dirDocs, localeDir); return { @@ -145,20 +143,23 @@ function getBreadcrumbs(path: string, baseDir: string): string[] { /** Turn a flat array of routes into a tree structure. */ function treeify(routes: Route[], baseDir: string): Dir { const treeRoot: Dir = makeDir(); - routes.forEach((doc) => { - const breadcrumbs = getBreadcrumbs(doc.id, baseDir); + routes + // Remove any entries that should be hidden + .filter((doc) => !doc.entry.data.sidebar.hidden) + .forEach((doc) => { + const breadcrumbs = getBreadcrumbs(doc.id, baseDir); - // Walk down the route’s path to generate the tree. - let currentDir = treeRoot; - breadcrumbs.forEach((dir) => { - // Create new folder if needed. - if (typeof currentDir[dir] === 'undefined') currentDir[dir] = makeDir(); - // Go into the subdirectory. - currentDir = currentDir[dir] as Dir; + // Walk down the route’s path to generate the tree. + let currentDir = treeRoot; + breadcrumbs.forEach((dir) => { + // Create new folder if needed. + if (typeof currentDir[dir] === 'undefined') currentDir[dir] = makeDir(); + // Go into the subdirectory. + currentDir = currentDir[dir] as Dir; + }); + // We’ve walked through the path. Register the route in this directory. + currentDir[basename(doc.slug)] = doc; }); - // We’ve walked through the path. Register the route in this directory. - currentDir[basename(doc.slug)] = doc; - }); return treeRoot; } |