A tool built with Go to generate files for Hugo using content from Contentful
This application for Hugo allows you to build a static site using the data stored at Contentful. It is built with Go and uses the Contentful Delivery API.
Note: The Connector and Hugo are built with Go, but for the normal usage of both of these you don't need to install Go.
Two things are needed:
Download them both here: releases.
Chose the the executable suiting your environment. If you can't find an executable that works for you, you can let Go build the executable from the source locally (see the Develop & Contribute step).
The config file needs to have the name config.json
and should look something like this:
{
"contentful": {
"spaceId": "",
"accessToken": ""
},
"hugo": {
"root": ""
}
}
Both the config file and executable need to be placed alongside your Hugo website, at the same level as your Hugo root directory.
.
├── hugo-site
├── config.json
└── contentful-hugo
To get the spaceId
and Contentful Delivery API accessToken
for your config, an API Key for your Contentful Space needs to be created.
This can be found in your app in Space settings -> API Keys
.
The root
property is the name of your Hugo root directory.
Add all of these properties to your config.json
.
At the moment you can get all the Entries from one existing Content Type at a time.
Specify with the flag -c
or -contentType
the ID of the Content Type you would like to add to Hugo.
contentful-hugo -c exampleContentType
The command will get all the published Entries from Contentful with the Content Type ID exampleContentType
. A Markdown
file is created for each Entry. In each file all the Contentful data of the given Entry is written into the Front Matter
(in JSON). All of the generated Markdowns are put in sections according
to the Entry's Content Type.
For the content that you now have in Hugo you can create templates. Accessing the properties out of Front Matter for your template can be done like so:
{{ .Param "contentful.fields.title"}}
For further help with Hugo, refer to their documentation.
If you want to contribute in development, simply:
go get github.com/thedodobird2/contentful-hugo
If you have problems or suggestions for improvement, just open an issue or a pull request.