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 🙏

© 2025 – Pkg Stats / Ryan Hefner

metalsmith-matters

v1.2.0

Published

A Metalsmith plugin to read file metadata from frontmatter

Downloads

23

Readme

metalsmith-matters Build Status

A Metalsmith plugin to read file metadata from frontmatter. Supports all frontmatter formats supported by the gray-matter library (including YAML, JSON, TOML, CSON, and more).

"But wait!" you say. "Doesn't Metalsmith already have frontmatter parsing built-in"? Well, yes. For now anyway. This plugin is an attempt to extract that functionality out of the Metalsmith core. Eventually the goal is to have frontmatter parsing removed from the Metalsmith core entirely in favor of this plugin or a similar one (see segmentio/metalsmith#157).

Even in the absence of that change though, this plugin has several key advantages over the built-in frontmatter parsing in Metalsmith. Firstly, it's composable with other plugins. For example, you could use it with metalsmith-branch to turn on frontmatter parsing for only a subset of files, or you could place it after metalsmith-s3 in the plugin list so that it parses frontmatter in downloaded files.

Secondly, this plugin provides a way to pass options to the underlying frontmatter parsing library, gray-matter. This allows you to do things like change the delimiter used to separate frontmatter from the rest of the file, or set TOML as the default frontmatter format.

Thirdly, this plugin provides an additional feature allowing parsed frontmatter to be automatically namespaced under a single key (e.g. page.keys instead of keys).

These are all things you can't do with Metalsmith's built-in frontmatter parsing.

Installation

npm install --save metalsmith-matters

CLI Usage

After installing metalsmith-matters, simply add the metalsmith-matters key to the plugins in your metalsmith.json file. Be sure to include it before any plugins which need to use the metadata in your frontmatter, or which expect as input files with no frontmatter header. Generally speaking, this means that metalsmith-matters should be the first plugin in the list.

{
  "frontmatter": false, // Disable built-in frontmatter parsing (recommended)
  "plugins": {
    "metalsmith-matters": {
      // Options
    }
    // Other plugins...
  }
}

JavaScript Usage

After installing metalsmith-matters, you can require metalsmith-matters in your code, then call the exported value to initialize the plugin and pass the result to Metalsmith.use (just as you would with any other Metalsmith plugin). Again, be sure to use metalsmith-matters before any plugins which need to use the metadata defined your frontmatter, or which expect as input files with no frontmatter header. Generally speaking, this means that metalsmith-matters should be the first plugin in the list.

var frontmatter = require('metalsmith-matters');

Metalsmith(__dirname)
  .frontmatter(false) // Disable built-in frontmatter parsing (recommended)
  .use(frontmatter({
    // Options
  }))
  .use(/* Other plugins... */)
  .build(function(err) {
    if (err) throw err;
  });

Options

namespace

Type: string
Default: undefined

Namespace all parsed data under a single key.

Example

Your frontmatter:

---
title: My title
author: Joe Writer
---

In the JavaScript:

  // new Metalsmith…
  .use(frontmatter({ namespace: 'page' }))
  // …build()

Now in your HTML, you can access the metadata like this (example with Handlebars):

  <h1>{{ page.title }}</h1>
  <p>Author: {{ page.author }}</p>

gray-matter Options

metalsmith-matters also supports all the options supported by gray-matter, metalsmith-matters' underlying frontmatter parsing library (it's the same one used by the Metalsmith core). These include:

  • parser
  • eval
  • lang
  • delims

For details on how to use these options, see the documentation for gray-matter.