You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

contentful-static

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-static

Save data from a Contentful space to a local JSON file

1.4.2
latest
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
Source

Simple static site generator for contentful

What it's for

A CLI tool to generate a site from templates + data from a contentful space

How to use it

To build a site from a space using the templates in templatesFolder

contentful-static -a yourAccessToken yourSpaceId templatesFolder/ dest/

Template building

Each entry in your contentful data is matched against a template by checking it's contentType name.

Template variables

Availiable in the template context are

Name
entryThe entry for this template
contentThe entire contentful data object.
entriesAll entries
includesHTML data for all entries already rendered. Key is id.
include(entry)A function (shorthand for direct usage of include). Takes either a list of entries or an entry and returns it's html
debug(obj)Print debug for an object

A note on templates

As a default contentful-static uses the template language nunjucks. But since it uses consolidate in theory any other templating language can be used.

Install with NPM

npm install -g contentful-static

API

var contentfulStatic = require('contentful-static');

3. Configure

contentfulStatic.config({
    // Path to templates.
    templates: 'templates'
    // Your Contentful space ID
    space: 'my12space34id',
    // Contentful Access Token
    accessToken: '5fdae8a3myacc3sst0ken573962'
});

4. Fetch


// With promise
contentfulStatic.sync().then(function(json) {
  console.log('contentful-static: data stored successfully!', json);
}, function (err) {
  console.log('contentful-static: data could not be fetched');
});

// With callback
contentfulStatic.sync(function(err, json) {
    if(err) {
        console.log('contentful-static: data could not be fetched');
        return false;
    }
    console.log('contentful-static: data fetched successfully!', json);
});

4. Render


// With promise
contentfulStatic.render(json).then(function(htmls) {
  // Rendered data is an object where key is entry sys id and value is its HTML
  console.log(htmls);
}, function (err) {
  console.log('Could not render templates');
});

// With callback
contentfulStatic.render(json, function(err, htmls) {
    // Handle callback
});

FAQs

Package last updated on 20 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts