A Metalsmith plugin to automatically create collections from files' metadata.
A common use case is grouping blog articles by one or more tags that are defined in frontmatter, for example:
---
title: Using metalsmith-multi-collections in your website
tags:
- metalsmith
---
This plugin is helpful!
npm install --save metalsmith-multi-collections
import Metalsmith from 'metalsmith';
import multiCollections from 'metalsmith-multi-collections';
Metalsmith(__dirname)
.use(multiCollections.default({
// options here
}))
.build((err) => {
if (err) {
throw err;
}
});
Type: string
A micromatch
glob pattern to find input files to group into collections.
Example: "blog/**"
Type: string
The frontmatter key of where to find values.
Example: "tags"
for the blog article example:
---
title: Using metalsmith-multi-collections in your website
tags:
- metalsmith
---
This plugin is helpful!
Type: string
Default: "{val}"
The resulting collection name. The token {val}
is replaced with any and all values found in the key
option above.
Example: "blog/tag/{val}"
Type: object
@metalsmith/collections
options to use when generating collections.
Example: you may want to provide sortBy
, reverse
, limit
, or other options:
{
settings: {
sortBy: (a, b) => DateTime.fromJSDate(a.date).toMillis() - DateTime.fromJSDate(b.date).toMillis(),
reverse: true
}
}