nuxt / content

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

Add pagination support #1918

Open Barbapapazes opened 1 year ago

Barbapapazes commented 1 year ago

l'm currently building a large application using Content. In order to have a better UX, I'm looking for a way to paginate data.

Like find or findOne we could have paginate. (I can simulare this using skip and limit but I don't have a way to count all).

const data = queryContent('/categories').paginate(<page:number>, <limit:number>)

Behind the scene, Content fetch data, count and create pagination to return

{
  data: <data: any[]>
  meta: {
    total: <number>,
    perPage: <number>,
    currentPage: <number>,
    lastPage: <number>,
    firstPage: <number>
  }
}

Reference:

Barbapapazes commented 1 year ago

In the same time, a count method could be awesome.

bordermedia commented 1 year ago

+1 for adding a count method. Currently have to run a queryContent for all content to get total, then perform a pagination calc, then re-run queryContent with skip and limit.

wokalek commented 1 year ago
// fetch the next 5 articles
const articles = await queryContent('articles')
    .skip(5)
    .limit(5)
    .find()
Barbapapazes commented 1 year ago
// fetch the next 5 articles
const articles = await queryContent('articles')
    .skip(5)
    .limit(5)
    .find()

Yes but No because with this approach, you won't be able to know when you reach the last page and you will have to have another request to have the number of articles. The request to get the number of articles, you will transfert all content, not just a simple number.

wokalek commented 1 year ago
// fetch the next 5 articles
const articles = await queryContent('articles')
    .skip(5)
    .limit(5)
    .find()

Yes but No because with this approach, you won't be able to know when you reach the last page and you will have to have another request to have the number of articles. The request to get the number of articles, you will transfert all content, not just a simple number.

Yeah, I do not argue, it is necessary in the nuxt/content