From bda0cd0bd09574740cc831010f9bd7f4f6d8ffa3 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Fri, 3 Jun 2022 22:03:30 +1000 Subject: [PATCH] fix(navigation): allow navigation opt-out with `navigation: false` (#1208) * fix(navigation): allow navigation opt-out with `navigation: false` * fix: use existing where query --- src/runtime/server/api/navigation.ts | 8 +++++++- test/features/navigation.ts | 6 ++++++ test/fixtures/basic/content/navigation-disabled.md | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) 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..46c5c54ae 100644 --- a/src/runtime/server/api/navigation.ts +++ b/src/runtime/server/api/navigation.ts @@ -13,7 +13,13 @@ export default defineEventHandler(async (event) => { * Partial contents are not included in the navigation * A partial content is a content that has `_` prefix in its path */ - _partial: false + _partial: false, + /** + * Exclude any pages which have opted out of navigation via frontmatter. + */ + navigation: { + $ne: false + } }) .find() 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