0.0.3 • Published 5 months ago

metalsmith-multi-collections v0.0.3

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
5 months ago

metalsmith-multi-collections

npm: version npm: downloads

Snyk: vulnerabilities codecov: coverage license

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-collections

JavaScript 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
  }
}

Changelog

Changelog

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

6 months ago