content icon indicating copy to clipboard operation
content copied to clipboard

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

Open gitFoxCode opened this issue 3 years ago • 5 comments

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

gitFoxCode avatar Dec 30 '22 11:12 gitFoxCode

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.

ManasMadrecha avatar Jan 01 '23 16:01 ManasMadrecha

You can use regex to fetch both directories:

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

farnabaz avatar Jan 12 '23 13:01 farnabaz

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

gitFoxCode avatar Jan 19 '23 12:01 gitFoxCode

@gitFoxCode Sort by slug, rather than path.

ManasMadrecha avatar Jan 19 '23 12:01 ManasMadrecha

@gitFoxCode Sort by slug, rather than path.

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

MrIsaacs avatar Apr 03 '24 22:04 MrIsaacs