content icon indicating copy to clipboard operation
content copied to clipboard

queryContent matches on start of path not directory name

Open damieng opened this issue 1 year ago • 1 comments

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:

  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

damieng avatar Jul 26 '24 09:07 damieng

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] avatar Sep 25 '24 02:09 github-actions[bot]

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

github-actions[bot] avatar Oct 25 '24 02:10 github-actions[bot]