Metalsmith plugin to allow defining Collections by using file conventions.
npm install --save metalsmith-collections-convention
If you are using the command-line version of Metalsmith, you can install via npm, and then add the metalsmith-jstransformer
key to your metalsmith.json
file:
{
"plugins": {
"metalsmith-collection-convention": {}
}
}
If you are using the JS Api for Metalsmith, then you can require the module and add it to your .use()
directives:
var collections = require('metalsmith-collection-convention');
metalsmith.use(collections());
There are two different methods of define collections. First, by using <name>.collection
file convention, or by defining the collection in source file meta-data.
Each collection is constucted through defining files named <name>.collection
.
src/articles.collection
---
pattern: 'articles/*.md'
sortBy: 'date'
reverse: true
---
This is the collection of articles. It is available at:
metalsmith.metadata().articles
You can define which collection source files are placed by placing them in the meta-data.
src/articles/foo.md
---
collection: articles
---
This article will appear in the articles collection. It is available at:
metalsmith.metadata().articles
src/documents/bar.md
---
collection:
name: documents
sortBy: title
---
This article will appear in the documents collection, sorted by title. It is
available at:
metalsmith.metadata().documents
MIT