No description
Find a file
Ian Storm Taylor f549d4a4b0 update readme
2014-03-06 14:52:52 -08:00
lib add shorthand for pattern matching 2014-03-06 14:40:19 -08:00
test add shorthand for pattern matching 2014-03-06 14:40:19 -08:00
.gitignore first commit 2014-02-05 15:06:46 -08:00
History.md 0.1.0 2014-03-06 14:46:01 -08:00
Makefile first commit 2014-02-05 15:06:46 -08:00
package.json 0.1.0 2014-03-06 14:46:01 -08:00
Readme.md update readme 2014-03-06 14:52:52 -08:00

metalsmith-collections

A Metalsmith plugin that groups files together into collections, which it adds to the global metadata. This is helpful for things like blog posts, where you want to display an index.

Features

  • can match files by collection metadata
  • can match files by pattern
  • adds collection to global metadata
  • adds next and previous references to each file

Installation

$ npm install metalsmith-collections

Usage

There are two ways to create collections:

  • by pattern - this is just passing a globing pattern that will group any files that match into the same collection.
  • by metadata - this is adding a specific collection metadata field to each item that you want to add to a collection.

The simplest way to create a collection is to use a pattern to match the files you want to group together:

var collections = require('metalsmith-collections');

metalsmith.use(collections({
  articles: '*.md'
}));

Which is just a shorthand. You could also add additional options:

metalsmith.use(collections({
  articles: {
    pattern: '*.md',
    sortBy: 'date',
    reverse: true
  }
}));

But you can also match based on a collection property in each file's metadata by omitting a pattern, and adding the property to your files:

metalsmith.use(collections({
  articles: {
    sortBy: 'date',
    reverse: true
  }
}));
---
title: My Article
collection: articles
date: 2013-02-21
---

My article contents...

All of the files with a matching collection will be added to an array that is exposed as a key of the same name on the global Metalsmith metadata.

CLI Usage

All of the same options apply, just add them to the "plugins" key in your metalsmith.json configuration:

{
  "plugins": {
    "metalsmith-collections": {
      "articles": {
        "sortBy": "date",
        "reverse": true
      }
    }
  }
}

License

MIT