close

  menu      DavidRodenas
CONTACT  

grunt-frontmatter

A grunt task able to extract YAML front-matter from files and integrate all into a single JSON file.


Overview

This is a grunt task able to generate JSON data from front-matter metadata present in multiple files.

As example, given the following directory structure:

.
├── Gruntfile.coffee
├── package.json
└── source
    ├── articles
    │   ├── bellflower.md    <--
    │   ├── fiddler.html     <--
    │   └── healthy.md       <--
    ├── index.html
    ├── styles.css
    └── app.js

it can generate articles.json file as follows:

.
├── Gruntfile.coffee
├── package.json
├── source
└── release
    └── articles.json        <--

Setup

Install it in your project with npm:

$ npm install --save-dev grunt-frontmatter

After it configure your Gruntfile.js as follows:

/** Gruntfile.js */
module.exports = function(grunt) {

  // Project tasks configurations
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json')
    
    // (C) Tasks configurations here
    frontmatter: {
        options: {
            minify: true,
            width: 200,
        },
        files: {
            'release/articles.json': ['source/articles/*.md']
        },
    }
  });

  // (L) Load here grunt plugins with tasks
  grunt.loadNpmTasks('grunt-frontmatter');

  // (T) Add here your task(s) 
  grunt.registerTask('default', [ ... ]);
};

It should reproduce the example shown in the overview.