Fetch entries from a Contentful space and write them as Markdown files.
Use Contentful as a GUI to edit content for a static website made with Jekyll.
contentful2md can help you if you are in the following context:
In this situation, it is common to use a dynamic Content Management System (like WordPress, for example) to build the website because it provides a GUI and writers find it easy to use.
Though, we believe that in many cases static websites are a more suitable solution than dynamic CMS: they are very easy to host, easier to customize, faster and more secure.
To allow writers to focus on writing and not on installing and keeping up-to-date the development environment, we provide a solution that makes it very easy to use the nice GUI of Contentful to write content that will end up in a Jekyll website.
Mostly at the beginning of the project:
On a regular basis:
In your Jekyll project:
npm install contentful2md
package.json
:{
"scripts": {
"contentful2md": "contentful2md"
}
}
npm run contentful2md
Configuration is done using environment variables. The following variables can/must be configured:
Name | Default Value | Description |
---|---|---|
CONTENTFUL_SPACE |
Space ID, as given by Contentful. | |
CONTENTFUL_ACCESS_TOKEN |
Access token, as given by Contentful. Depending on the value of CONTENTFUL_PREVIEW , this should be the Content Delivery API or the Content Preview API. |
|
CONTENTFUL_PREVIEW |
false |
If the value if true , use the Preview API. Else use the Delivery API. |
CONTENTFUL_CONTENT_TYPE_ID |
The ID of the Content Type you want to fetch, as you defined in the Content Model of your space on Contentful. | |
CONTENTFUL_LOCALE |
The locale to fetch. For example: fr-FR . |
|
CONTENTFUL_CONTENT_FIELD |
content |
The field of your Content Type that should be considered as the main content and put in the body of the Markdown file. |
CONTENTFUL_SLUG_FIELD |
slug |
The field of your Content Type that correspond to the URL your content should take. It will be used to name the Markdown file, so it must be unique. |
OUTPUT_DIR |
The path to a directory where Markdown files should be created. If the directory does not exist, it will be created. If it exists, its files might be overridden. |
Every variable must be defined, except those which have a default value.
There are several ways to define them (which can be mixed):
export CONTENTFUL_SPACE="..."
# ...
npm run contentful2md
CONTENTFUL_SPACE="..." npm run contentful2md