modiimedia / contentful-hugo

A CLI tool that pulls data from Contentful and turns it into markdown files for Hugo and other static site generators. It also includes an express server that can be used for local development and content previews

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for Contentful Preview API access token

noorhammad opened this issue · comments

I have multiple environments eg. dev / staging / production

In my dev / staging environments I would like getEntries to pull all Entries including unpublished so that I can preview them.

I can access unpublished entries by making two changes to the Contentful client config:

  • Change accessToken from Content Delivery API to Content Preview API access token
  • Change host from cdn.contentful.com to preview.contentful.com

I have forked and created a proof of concept here: https://github.com/noorhammad/contentful-hugo/tree/allow-preview

  • Adds new .env variable CONTENTFUL_PREVIEW_TOKEN
  • Adds flag --preview when running contentful-hugo which configures accessToken and host accordingly.

Both default to the standard config.

Would love some feedback on this.

@noorhammad what you've done looks great. I played around with it on my machine and it does what it should.

Why don't you create a pull request and we can merge it into the master branch? Please pull the latest changes from the master when you do so as well.

Preview API supported has now been added with #15

I took what you started and added some additional features to it.