Happy path to directory listings? [V3] #3185
Replies: 2 comments
-
Feedback would still be welcome. |
Beta Was this translation helpful? Give feedback.
-
TL;DR: queryCollectionNavigation() gives you the full tree, then use the built-in helpers to slice it for the current folder. For a “directory listing” page (e.g. /docs/platform/billing), call findPageChildren on that path and render only those items. You can also build breadcrumbs with findPageBreadcrumb. TL;DR: You don’t have to render the whole nav. Fetch the collection’s navigation once and then derive just the current folder’s items with the built-in helpers (no manual tree-slicing needed). Directory listing for the current folder: <script setup lang="ts"> import { findPageChildren } from '@nuxt/content/utils' const route = useRoute() // Get the full tree once for your collection (e.g. 'docs') const { data: navigation } = await useAsyncData('nav', () => queryCollectionNavigation('docs') ) // Only the children under the current path (treat index.md as child if you like) const children = computed(() => navigation.value ? findPageChildren(navigation.value, route.path, { indexAsChild: true }) : [] ) </script>
queryCollectionNavigation() returns the tree for a collection, and findPageChildren() extracts just the items under a given path. (Alternative) Query content by path queryCollection() supports .where() and .path() to filter pages within a collection. Extras:
This gives you a “Docs > Platform > Billing” breadcrumb and a clean directory-only listing on “Billing” without custom tree-surgery. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am looking at
queryCollectionNavigation
here:https://content.nuxt.com/docs/utils/query-collection-navigation
If I understand correctly, it always dumps the whole navigation?
Now, my project does not have a permanent side bar navigation like with the documentation of Nuxt Content itself. It has a breadcrumb like this:
Docs > Platform > Billing
. Each of those items represents a folder in the markdown structure:So when clicking on the billing headline, I'd ideally like to show a directory listing of only the items in that directory.
Mapped to the Nuxt Content Docs this means that this page:
https://content.nuxt.com/docs/utils/
would actually show the contents of that folder instead of redirecting.
So far I manually strip down the navigation to the current route (via Vue). But that code doesn't look not nice and feels unnecessarily complex for something that looks like a very common use case to me. So maybe I am missing the correct way to do it?
Beta Was this translation helpful? Give feedback.
All reactions