From 6772b5fed364821dc9c7ffac3d341897aca50695 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Fri, 3 Jun 2022 18:09:20 +1000 Subject: [PATCH 1/2] fix(navigation): allow navigation opt-out with `navigation: false` --- src/runtime/server/api/navigation.ts | 8 ++++++++ test/features/navigation.ts | 6 ++++++ test/fixtures/basic/content/navigation-disabled.md | 7 +++++++ 3 files changed, 21 insertions(+) create mode 100644 test/fixtures/basic/content/navigation-disabled.md diff --git a/src/runtime/server/api/navigation.ts b/src/runtime/server/api/navigation.ts index 4f11e3063..f6d85a803 100644 --- a/src/runtime/server/api/navigation.ts +++ b/src/runtime/server/api/navigation.ts @@ -8,6 +8,14 @@ export default defineEventHandler(async (event) => { const query: Partial = getContentQuery(event) const contents = await serverQueryContent(event, query) + .where({ + /** + * Exclude any pages which have opted out of navigation via frontmatter. + */ + navigation: { + $ne: false + } + }) .where({ /** * Partial contents are not included in the navigation diff --git a/test/features/navigation.ts b/test/features/navigation.ts index 3a72a9fc6..647130db0 100644 --- a/test/features/navigation.ts +++ b/test/features/navigation.ts @@ -53,5 +53,11 @@ export const testNavigation = () => { expect(item.title).toEqual(String(fibo[index])) }) }) + + test('Should remove `navigation-disabled.md` content', async () => { + const list = await $fetch('/api/_content/navigation/') + const hidden = list.find(i => i._path === '/navigation-disabled') + expect(hidden).toBeUndefined() + }) }) } diff --git a/test/fixtures/basic/content/navigation-disabled.md b/test/fixtures/basic/content/navigation-disabled.md new file mode 100644 index 000000000..73a14154e --- /dev/null +++ b/test/fixtures/basic/content/navigation-disabled.md @@ -0,0 +1,7 @@ +--- +navigation: false +--- + +# Hidden from navigation + +Basic description From 200027e9dfda5563d264786782416f348c03d682 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Fri, 3 Jun 2022 18:12:57 +1000 Subject: [PATCH 2/2] fix: use existing where query --- src/runtime/server/api/navigation.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/runtime/server/api/navigation.ts b/src/runtime/server/api/navigation.ts index f6d85a803..46c5c54ae 100644 --- a/src/runtime/server/api/navigation.ts +++ b/src/runtime/server/api/navigation.ts @@ -9,6 +9,11 @@ export default defineEventHandler(async (event) => { const contents = await serverQueryContent(event, query) .where({ + /** + * Partial contents are not included in the navigation + * A partial content is a content that has `_` prefix in its path + */ + _partial: false, /** * Exclude any pages which have opted out of navigation via frontmatter. */ @@ -16,13 +21,6 @@ export default defineEventHandler(async (event) => { $ne: false } }) - .where({ - /** - * Partial contents are not included in the navigation - * A partial content is a content that has `_` prefix in its path - */ - _partial: false - }) .find() const dirConfigs = await serverQueryContent(event).where({ _path: /\/_dir$/i, _partial: true }).find()