nuxt / content

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

enhancements: pagination helpers #1389

Open bloodf opened 2 years ago

bloodf commented 2 years ago

Is your feature request related to a problem? Please describe

When creating some application with Nuxt-Content, you may find yourself in need of pagination with possible pages. Like https://github.com/vuestorefront/developer.vuestorefront.io

My solution was to create queries to fetch all files in a specific query, with only some tags, to get the total available in the query without the skip.

Describe the solution you'd like

In the query builder, if possible, add a new function, pagination, where it will return the same as skip and limit but with predefined pagination helpers, like returning the object.

type PaginatedResult = {
  data: Result[]
  total: number
  pages: Page[]
  previousPage: number;
  nextPage: number;
  firstPage: number;
  lastPage: number;
}

In this pagination function, we can pass the limit of items and pages to display.

Describe alternatives you've considered

Have two function to fetch basic data like here https://github.com/vuestorefront/developer.vuestorefront.io/blob/main/store/videos/videoList.ts

YoonTso commented 2 years ago

+1, now, i have to use queryContent to get the length of all page first, then use limit and skip, but I realize since I already get all pages data, I could just use the array data of all pages combining with Array slice. hope there would be a more concise method like count, return the count of all page for custom pagination component.

luxterful commented 2 years ago

i would love to see a feature like this!

mrleblanc101 commented 1 year ago

Bump, this would be very useful ! Currently, we need to do a second query to get the total number of post and it's not efficient as the query will become longer and longer over time as we add more articles...