metalsmith-multi-collections
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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

Package Sidebar

Install

npm i metalsmith-multi-collections

Weekly Downloads

0

Version

0.0.3

License

GPL-3.0-or-later

Unpacked Size

47.6 kB

Total Files

6

Last publish

Collaborators

  • emmercm