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

ContentList only showing one document #1141

Closed
ineation opened this issue May 25, 2022 · 4 comments
Closed

ContentList only showing one document #1141

ineation opened this issue May 25, 2022 · 4 comments

Comments

@ineation
Copy link

ineation commented May 25, 2022

Environment

  • Operating System: Linux
  • Node Version: v16.15.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: npm@8.5.5
  • Builder: vite
  • User Config: modules, content
  • Runtime Modules: @nuxt/content@2.0.0
  • Build Modules: -

Reproduction

https://github.com/ineation/nuxt-contentlist-issue

In the home page, I have two ContentListcomponents:

  • one should (if I understand correctly) show all the docs in the content/articles directory but it shows only the document at that specific route
  • one shows only the documents because I have specified a path prop with an empty string (if I remove the prop it does not show any content).

Describe the bug

My understanding of ContentList from the default example in the doc, is that it should fetch all the documents that are at the root of a directory but it only fetches the one document specified by the path prop (like it does for ContentDoc, which makes sense for ContentDoc but not really for ContentList)

Also when we don't use the path prop it does not fetch any single document.

The only way I have found to fetch several documents is to specify path="" with an empty string but that does not seems like normal.

Additional context

Please note that I am a newbie and that the root cause of the issue might be me :-)

Logs

No response

@GerryWilko
Copy link
Contributor

GerryWilko commented May 25, 2022

Ah excellent! I was just banging my head against this. Good to know I'm not alone 😄

It seems that ContentQuery isn't quite working as I would expect. Unless I'm missing something (or we both are) this should allow you to query a content folder but it behaves a little strangely at present.

From my testing if you query a folder full of content (I have been testing with MD files) it will show as empty when using a content query. Adding an index.md file will then list there is one page in that directory with no children or any indication there may be other files present in that directory.

There seems to be a prop on ContentQuery called find which if set to surround ends up with some nulls being returned.

I've been reading through the src and I can't see what might be going wrong.

@Atinux
Copy link
Member

Atinux commented May 25, 2022

From what I see, it seems that it matches articles/index.md, I also tested with articles.md and it returns only one document.

I suspect because of the generated query for path:

Screenshot 2022-05-25 at 12 50 46@2x

I think when using <ContentList>, we shall generate a regex similar to https://github.com/nuxt/content/blob/main/src/runtime/composables/query.ts#L44

Can you open a PR for it @farnabaz or @Tahul? It will be the occasion to add a test case for <ContentQuery> too.

@GerryWilko
Copy link
Contributor

I've resolved this issue in PR #1143

Here you can see in the screenshot when patched this content query and the ContentList is working as expected:
image

I also created a dummy secondary directory with a sub-directory called real-content and you can see that these files are correctly not shown.

Tahul added a commit that referenced this issue May 25, 2022
Co-authored-by: Yaël Guilloux <yael.guilloux@gmail.com>
@farnabaz
Copy link
Member

Fixed in #1143 and released in v2.1.0 🎉

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

4 participants