Skip to content

Commit

Permalink
fix(navigation): allow navigation opt-out with navigation: false (#…
Browse files Browse the repository at this point in the history
…1208)

* fix(navigation): allow navigation opt-out with `navigation: false`

* fix: use existing where query
  • Loading branch information
harlan-zw authored and farnabaz committed Sep 7, 2022
1 parent ac9fa5b commit 1a8e770
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/runtime/server/api/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 6 additions & 0 deletions test/features/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
}
7 changes: 7 additions & 0 deletions test/fixtures/basic/content/navigation-disabled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
navigation: false
---

# Hidden from navigation

Basic description

0 comments on commit 1a8e770

Please sign in to comment.