npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

contentful-metalsmith

v0.11.0

Published

A Metalsmith's plugin to get content from Contentful

Downloads

193

Readme

contentful-metalsmith

Build Status Coverage Status

A Metalsmith' plugin to generate files using content from Contentful

About

This plugin for metalsmith allows you to build a static site using the data stored at Contentful. It is built on top of the Contentful JavaScript Client.

Example

To get an idea on how this works, you can check out an example blog site which is completely generated using contentful-metalsmith.

Getting started

Install

$ npm install contentful-metalsmith

Configure required globals

When you use metalsmith using the cli edit your metalsmith.json and add contentful-metalsmith in the plugins section.

// metalsmith.json

{
  "source": "src",
  "destination": "build",
  "plugins": {
    "contentful-metalsmith": {
      "access_token": "YOUR_CONTENTFUL_ACCESS_TOKEN",
      "space_id": "YOUR_CONTENTFUL_SPACE_ID"
    }
  }
}

When you use the JavaScript Api add contentful-metalsmith to the used plugins.

metalsmith.source('src')
metalsmith.destination('build')

metalsmith.use(require('contentful-metalsmith')({ 'access_token' : 'YOUR_CONTENTFUL_ACCESS_TOKEN' }))

Global parameters:

  • access_token
  • space_id

You can find the access_token and space_id in your app at APIs -> Content delivery API Keys.


To read more on all global parameters and settings read the global settings documentation.

Create files based on the files defined in your source folder

We're considering that you use metalsmith-layouts for file rendering. That for the layout key is used for rendered source files and child templates.

source/posts.html

---
title: metalsmith-contentful file
contentful:
  content_type: post
  entry_filename_pattern: blog/post-${ sys.id }
  entry_template: post.html
layout: posts.html
---

[OPTIONAL CONTENT]

layouts/posts.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>{{title}}</title>
  <meta name="description" content="No description">
  <meta name="author" content="Contentful">
  <link rel="stylesheet" href="scss/style.css?v=1.0">
</head>
<body>
  <ul>
    <!-- available data fetched from contentful -->
    {{#each data.entries }}
      <li>
        <h2>{{fields.title}}</h2>
        <p>{{fields.description}}</p>
        <p><a href="{{_fileName}}">Read more</a></p>
      </li>
    {{/each}}
    </ul>
    {{contents}}
</body>
</html>

layouts/post.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>{{data.fields.title}}</title>
  <meta name="description" content="No description">
  <meta name="author" content="Contentful">
  <link rel="stylesheet" href="scss/style.css?v=1.0">
</head>
<body>
  <h1>{{data.fields.title}}<h1>
  <p>{{data.fields.description}}</p>

  {{contents}}
</body>
</html>

This example will

  • render posts.html providing data of the entries of content type post
  • render several single files with the template post.html providing the data of a particular post

To read more on source file parameters and settings read the source file documentation.

Debugging

This project uses debug under the hood. If you want to see all debug messages by contentful-metalsmith you can do so by setting a wildcard debug environment variable.

$ DEBUG=metalsmith-contentful* your command

Currently there are two different variables available to give you information about a specific area:

  • metalsmith-contentful-files - get information about file data before/after processing
  • metalsmith-contentful-queries - get information about queries and related files

For example if you want to see what files went into the plugin and got out again:

$ DEBUG=metalsmith-contentful-files your command

:point_up: This debug information is good to validate what data is available in metalsmith-layouts.

License

MIT