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

contentful2md

v1.0.3

Published

Fetch entries from a Contentful space and write them as Markdown files

Downloads

8

Readme

contentful2md

LICENSE npm Get help on Codementor

Fetch entries from a Contentful space and write them as Markdown files.

Motivation

Use Contentful as a GUI to edit content for a static website made with Jekyll.

contentful2md can help you if you are in the following context:

  • you have a static website, built by developers using Jekyll
  • you want to enable writers to edit some of the website content (for example: a blog)

In this situation, it is common to use a dynamic Content Management System (like WordPress, for example) to build the website because it provides a GUI and writers find it easy to use.

Though, we believe that in many cases static websites are a more suitable solution than dynamic CMS: they are very easy to host, easier to customize, faster and more secure.

To allow writers to focus on writing and not on installing and keeping up-to-date the development environment, we provide a solution that makes it very easy to use the nice GUI of Contentful to write content that will end up in a Jekyll website.

The Solution

Development

Mostly at the beginning of the project:

  • A space is created on Contentful
  • Developers configure one or several content types to define a model of the content that needs to be edited by writers, and create example content (that remains unpublished on Contentful)
  • Developers create a Jekyll project and develop the website they want
  • Developers use contentful2md to fetch the preview API of Contentful so that they can develop and test the parts of the website that display content from Contentful

Writing

On a regular basis:

  • Writers use Contentful to add or edit content, using the content types defined previously
  • Writers or developers use a CI/CD system (such as GitLab CI) to:
    • fetch content from Contentful (using contentful2md)
    • build the website (using Jekyll)
    • deploy it

Usage

In your Jekyll project:

  • install via npm: npm install contentful2md
  • add the following script in package.json:
{
  "scripts": {
    "contentful2md": "contentful2md"
  }
}
  • configure using environment variables (see next section)
  • run: npm run contentful2md

Configuration

Configuration is done using environment variables. The following variables can/must be configured:

| Name | Default Value | Description | |---|---|---| | CONTENTFUL_SPACE | | Space ID, as given by Contentful. | | CONTENTFUL_ACCESS_TOKEN | | Access token, as given by Contentful. Depending on the value of CONTENTFUL_PREVIEW, this should be the Content Delivery API or the Content Preview API. | | CONTENTFUL_PREVIEW | false | If the value if true, use the Preview API. Else use the Delivery API. | | CONTENTFUL_CONTENT_TYPE_ID | | The ID of the Content Type you want to fetch, as you defined in the Content Model of your space on Contentful. | | CONTENTFUL_LOCALE | | The locale to fetch. For example: fr-FR. | | CONTENTFUL_CONTENT_FIELD | content | The field of your Content Type that should be considered as the main content and put in the body of the Markdown file. | | CONTENTFUL_SLUG_FIELD | slug | The field of your Content Type that correspond to the URL your content should take. It will be used to name the Markdown file, so it must be unique. | | OUTPUT_DIR | | The path to a directory where Markdown files should be created. If the directory does not exist, it will be created. If it exists, its files might be overridden. |

Every variable must be defined, except those which have a default value.

There are several ways to define them (which can be mixed):

  • in your environment (Continous Integration often allow that)
  • in a shell script:
export CONTENTFUL_SPACE="..."
# ...

npm run contentful2md
  • directly in the command line: CONTENTFUL_SPACE="..." npm run contentful2md