Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queryContent matches on start of path not directory name #2732

Open
damieng opened this issue Jul 26, 2024 · 0 comments
Open

queryContent matches on start of path not directory name #2732

damieng opened this issue Jul 26, 2024 · 0 comments

Comments

@damieng
Copy link
Contributor

damieng commented Jul 26, 2024

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: pnpm@9.5.0

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 damieng changed the title queryContent matches on start of path not directory queryContent matches on start of path not directory name Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant