0.0.3 • Published 2 years ago
metalsmith-multi-collections v0.0.3
metalsmith-multi-collections
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!Installation
npm install --save metalsmith-multi-collectionsJavaScript Usage
import Metalsmith from 'metalsmith';
import multiCollections from 'metalsmith-multi-collections';
Metalsmith(__dirname)
.use(multiCollections.default({
// options here
}))
.build((err) => {
if (err) {
throw err;
}
});Options
pattern (required)
Type: string
A micromatch glob pattern to find input files to group into collections.
Example: "blog/**"
key (required)
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!collection (optional)
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}"
settings (required)
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
}
}