gatsby-prismic-pagination
A little help to get your prismic.io based Gatsby project paginating.
Pre-requisites
- This plugin assumes you are using
gatsby-source-prismic-graphql
as your Gatsby source
Example usage
Create the paginated index pages:
In gatsby-node.js
:
const prismicPagination = exportscreatePages = async { const createPage = actions await }
Get all posts at once
The plugin will keep querying prismic until it has all your posts. This saves you writing your own loop for prismic's 20 post limit per query:
const allPosts = await // Still creates index pages // We now have all posts in a single array rather than in prismic paged responses// so it's easier to construct individual gatsby pagesallPosts
Template usage with next/previous links
;; ;
prismicConnectionArgs
Types of You can provide enum, string and array values here:
const prismicConnectionArgs: someEnumValue: 'date_DESC' // Enum value someMatchingStringSelector: `"myString"` someArray: "tag1" "tag2"}
This will be provided back to your template in the pageContext
which also makes them available in graphQl variables.
Other pagination options
If your emphasis is less on speed and SEO and more on publishing an article with instant feedback, then the source plugin has an example of run-time pagination: https://github.com/birkir/gatsby-source-prismic-graphql/tree/master/examples/pagination
Contributing
The plugin is written in typescipt and has rudimentary snapshot based coverage. Please see the package.json
for available scripts to build and test locally.
Todos
- Update tests to parse the graphql query in a structured manner rather than a string snapshot