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

grunt-frontmatter

v1.2.0

Published

Creates a json file from many files with yaml frontmatter

Downloads

52

Readme

grunt-frontmatters

Extract YAML front-matter from files to a single JSON file

The use case of grunt-frontmatter task is to strip all YAML front-matter pressent in multiple files (.html, .md, whatsoever) and combine them all in a single JSON file that can be loaded at once as a single file. It also is able to strip few firsts characters from each file to make a preview.

In addition to data already present in the YAML following fields are added:

  • preview of the actual body content
  • basename of the filename
  • md5 with the md5 signature of the file body

The "frontmatter" task

Pretend you have a folder structure like this:

.
├── Gruntfile.coffee
├── component.json
├── package.json
└── source
    ├── articles
    │   ├── bellflower.md    <--
    │   ├── fiddler.html     <--
    │   └── lottery.md       <--
    ├── favicon.ico
    ├── index.jade
    ├── style.styl
    ├── styles
    │   ├── h5bp.css
    │   ├── main.css
    │   └── normalize.css
    └── templates
        └── h5bp.jade

Each file in the articles directory has a bit of YAML front-matter metadata, like the title of the article, author, and tags. We want just the metadata from all three to be combined into a single JSON stringified file, called articles.json.

Now grunt release will build a release folder that looks like this:

.
├── Gruntfile.coffee
├── component.json
├── package.json
├── release
│   ├── articles
│   │   ├── bellflower.html
│   │   ├── fiddle.html
│   │   └── lottery.html
│   ├── articles.json            <---
│   ├── favicon.ico
│   ├── index.html
│   └── style.css
└── source

Configuring your "frontmatter" task

In your project's Gruntfile, add a section named frontmatter to the data object passed into grunt.initConfig().

frontmatter: {
    release: {
        options: {
            minify: true,
            width: 60
        },
        files: {
            'release/articles.json': ['source/articles/*.md']
        },
    }
}

Options

options.minify

Type: Boolean Default value: false

If true, then the JSON.stringify is instructed to strip unnecessary linebreaks, making the resulting .json file smaller.

options.dirname

Type: Boolean Default value: false

If true, then each entry has the dirname entry and object keys are composed with dirname + '/' + basename.

options.width

Type: Int | String Default value: "sentence"

If it is an Integer no more than width charactes from the Markdown file's body is saved in the preview element. Trailing ellipses are not added. If it is "sentence" saves until the first ". ", if it is a String number + "s" (ex: "2s") it is the number of sentences.

If preview defined in the frontmatter of a file, it takes it as preview and ignores this option.

More Examples

See examples.