nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.14k stars 628 forks source link

queryContent matches on start of path not directory name #2732

Closed damieng closed 4 weeks ago

damieng commented 3 months ago

Environment

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):

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:

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:

  1. Change the docs so that people know to do queryContent('articles/') (trailing slash)
  2. Fix the queryContent code to ensure a trailing slash wherever it is matching these parsed args

Additional context

No response

Logs

No response

github-actions[bot] commented 1 month ago

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.

github-actions[bot] commented 4 weeks ago

This issue was closed because it has been stalled for 30 days with no activity.