N
Nuxt4d ago
Grester

Nuxt Content Directory indexing too much?

According to https://content.nuxt.com/usage/content-directory the way to organise the content directories follows this example: content/index.md / content/blog/index.md /blog content/blog/hello.md /blog/hello I'm trying to use a <ContentList> to list the articles in my blog, however "{page} useContent()" also includes the index.md which I'm not interested. I've tested moving the index out of the folder to its parent, and renaming it again to the folder name, but then, useContent() doesn't recognize it as the blog folder, and ends up listing the root index and blog index files. Am I just approaching this the wrong way? Should I just add a meta tag and filter the useContent() to just load "posts" for example?
Nuxt Content
Content Directory - Nuxt Content
The Content module parses .md and .yaml files inside the content/ directory and provides paths according to the directory structure.
1 Reply
Grester
Grester4d ago
To those interested, what I ended up doing is something similar to this (I also had to do this for prev/next pages, you just have to adapt to it ignore pages where _stem ends in index)
const {page} = useContent()
const trimmedPath = page.value?._path?.substring(0, page.value._path.lastIndexOf("/")) || "";

const [prev, next] = await queryContent()
.where({'_path':{$contains: trimmedPath, $ne: trimmedPath }})
.only(['_path', 'title'])
.sort({ date: 1 })
.where({ isArchived: false || undefined })
.findSurround(page.value._path||"/")
</script>
const {page} = useContent()
const trimmedPath = page.value?._path?.substring(0, page.value._path.lastIndexOf("/")) || "";

const [prev, next] = await queryContent()
.where({'_path':{$contains: trimmedPath, $ne: trimmedPath }})
.only(['_path', 'title'])
.sort({ date: 1 })
.where({ isArchived: false || undefined })
.findSurround(page.value._path||"/")
</script>
Want results from more Discord servers?
Add your server