summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiDeoo2023-08-10 23:15:39 +0200
committerGitHub2023-08-10 23:15:39 +0200
commit35cd82e7f8622772a5155add99ad8baf61ae08a1 (patch)
treecdf6fef5fe26474bbe228c926c56f3efcdd6358e
parent14df4eda96eb2efc01fed4d991e44f66656f8b17 (diff)
downloadIT.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.md5
-rw-r--r--packages/starlight/__tests__/basics/navigation.test.ts1
-rw-r--r--packages/starlight/utils/navigation.ts35
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;
}