Next.js
The @content-collections/next
package allows a seamless integration of Content Collections into your Next.js app. This package provides a Next.js plugin that will automatically generate the content collections and add them to the build process.
Installation
First, install the required packages:
We have to install the following packages:
@content-collections/core
@content-collections/next
After installation we have to add a path alias for the generated collections to the tsconfig.json
:
Now we can add the Content Collections plugin to the Next.js config:
Warning
Ensure that withContentCollections
is the last plugin in the chain.
This is important because the plugin returns a Promise
, which is compatible with
Next.js, but other plugins
may not expect this behavior.
API
The package exports the following functions:
createContentCollectionPlugin
A function that creates the Next.js plugin for Content Collections.
withContentCollections
A functions which uses the createContentCollectionPlugin
with a the default options.
In most cases, you will only need to use the withContentCollections
function.
createContentCollectionPlugin
The function accepts one argument, an options object with the following properties. It then returns a function that takes the Next.js configuration object and provides a new configuration object with the Content Collections plugin included.
configPath
(required): Specifies the path to the Content Collections configuration file.
Example
withContentCollections
The function takes a single argument, a Next.js configuration object, and returns a new configuration object with the Content Collections plugin added.