nuxt / content

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

queryContent(['/path1/', '/path2/']) - downloading data from different paths simultaneously #1787

Open gitFoxCode opened 1 year ago

gitFoxCode commented 1 year ago

Is your feature request related to a problem? Please describe

I would like to download all articles, which unfortunately I have in two separate folders. To do this currently I have to download them individually and merge, or download everything from / and filter, which is not efficient. In the documentation is written out the possibility of using something like this:

// Create a query looking into content/articles/nuxt3 directory
const contentQuery = queryContent('articles', 'nuxt3')

I don't think it would be useful, after all, you can use just

const contentQuery = queryContent('articles/nuxt3')

It would be better to turn this into an option to download from multiple paths simultaneously

Describe the solution you'd like

The solution I would like is to be able to insert an array in the queryContent:

const allArticles = queryContent(['/blog/', '/news/'])

Describe alternatives you've considered

const news = await queryContent('/news/').find()
const blog = await queryContent('/blog/').find()
const allArticles = news.concat(blog)

Additional context

ManasMadrecha commented 1 year ago

You can simply download all files using / inside the queryContent, and then continuing in the same chain, you can use Content Module's where option to actually pick up only those two folders (blog, news).

This will be efficient compared to using normal JS filter.

farnabaz commented 1 year ago

You can use regex to fetch both directories:

const news = await queryContent().where({ _path: /^\/(news|blog)\// }).find()
gitFoxCode commented 1 year ago

You can use regex to fetch both directories:

const news = await queryContent().where({ _path: /^\/(news|blog)\// }).find()

Ok, and how could I sort the items the way I wanted with this? Because currently they behave "separately"

/news
    1.test.md
    3.article.md
/blog
   2.blog-article.md

Now its:

test, article, blog-article

I want:

test, blog-article, article
ManasMadrecha commented 1 year ago

@gitFoxCode Sort by slug, rather than path.

MrIsaacs commented 5 months ago

@gitFoxCode Sort by slug, rather than path.

Can also be sorted according to preference. Depending on various properties, such as categories or similar.