thedodobird2 / contentful-hugo

A tool for Hugo that pulls content from the Contentful API
Apache License 2.0
4 stars 1 forks source link
contentful go hugo

Contentful-Hugo Connector

GoDoc Build Status Go Report Card

A tool built with Go to generate files for Hugo using content from Contentful

About

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.

Getting started

Prerequisites

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.

Step 1: Download

Two things are needed:

Download them both here: releases.

executable

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).

config file

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

Step 2: Configure

contentful

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.

hugo

The root property is the name of your Hugo root directory.

Add all of these properties to your config.json.

Use

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

what happens

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.

now what?

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.

Develop & Contribute

If you want to contribute in development, simply:

go get github.com/thedodobird2/contentful-hugo

otherwise

If you have problems or suggestions for improvement, just open an issue or a pull request.