I'm trying to paginate the blog tags list page in a Gatsby site, the tags are defined in the frontmatter of the MDX files:
---
title: Blog Post Title
date: 2020-05-20
tags: ["Markdown", "Gatsby", "JavaScript"]
---
Paginating the posts is easy using limit and skip passed in the page context object:
query Posts($limit: Int!, $skip: Int!) {
allMdx(
sort: { fields: frontmatter___date, order: DESC }
limit: $limit
skip: $skip
) {
nodes {
...
}
}
But this doesn't apply for paginating the tags list page, this is going to limit and skip on allMdx, so we're going to get the same tag on multiple pages and also the totalCount is not going to be the total posts for a tags but the total for the limited posts.
query Tags($limit: Int!, $skip: Int!) {
allMdx(limit: $limit, skip: $skip) {
group(field: frontmatter___tags) {
fieldValue
totalCount
}
}
}
So how can I apply limit and skip on the group and not on the posts? What I can do is get all the tags for each page and use limit and skip in the component to show only the current page's tags, but I don't think this is the best way to do it.