Metalsmith Collections Convention Plugin
Metalsmith plugin to allow defining Collections by using file conventions.
Installation
npm install --save metalsmith-collections-convention
CLI
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:
JavaScript
If you are using the JS Api for Metalsmith, then you can require the module and add it to your .use()
directives:
var collections = ; metalsmith;
Usage
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.
Convention
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
Metadata
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: documentssortBy: title---This article will appear in the documents collection, sorted by title. It isavailable at:metalsmith.metadata().documents
License
MIT