queryContent matches on start of path not directory name
Environment
- Operating System: Linux
- Node Version: v21.7.3
- Nuxt Version: 3.12.4
- CLI Version: 3.12.0
- Nitro Version: 2.9.7
- Package Manager: [email protected]
Reproduced under WSL and native Windows.
Reproduction
Create a new content app with npx nuxi@latest init content-app -t content, then add a index.vue in the pages root with this content:
<template>
<ul>
<li v-for="article of articles" v:key="article._path">{{article._path }}</li>
</ul>
</template>
<script setup>
const { data: articles } = await useAsyncData(() => queryContent('articles').find())
</script>
Then finally create the following in the content folder (they can be just empty files):
- articlesofincorporation.md
- articles (directory)
- welcome-to-the-blog.md
Now running the page you'd expect to see just 1 item, "/articles/welcome-to-the-blog` based on the documentation for queryContent given that https://content.nuxt.com/composables/query-content says:
// Create a query looking into content/articles directory
const contentQuery = queryContent('articles')
But in fact you get two results:
- /articles/welcome-to-the-blog
- /articlesofincorporation
Describe the bug
queryContent arguments are matching against start of the path and not actually by directory name - in contradiction to the docs.
The fix will either be:
- Change the docs so that people know to do
queryContent('articles/')(trailing slash) - Fix the queryContent code to ensure a trailing slash wherever it is matching these parsed args
Additional context
No response
Logs
No response
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity.