
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
metalsmith-collections
Advanced tools
A Metalsmith plugin that adds collections of files to the global metadata.
A Metalsmith plugin that lets you group files together into an ordered collection, like blog posts. That way you can loop over them to generate an index, or add 'next' and 'previous' links between them.
collection metadatanext and previous references to each file in the collection$ npm install metalsmith-collections
There are two ways to create collections:
collection metadata field to each item that you want to add to a collection.The simplest way to create a collection is to use a pattern to match the files you want to group together:
var collections = require('metalsmith-collections');
metalsmith.use(collections({
articles: '*.md'
}));
Which is just a shorthand. You could also add additional options:
metalsmith.use(collections({
articles: {
pattern: '*.md',
sortBy: 'date',
reverse: true
}
}));
But you can also match based on a collection property in each file's metadata by omitting a pattern, and adding the property to your files:
metalsmith.use(collections({
articles: {
sortBy: 'date',
reverse: true
}
}));
---
title: My Article
collection: articles
date: 2013-02-21
---
My article contents...
All of the files with a matching collection will be added to an array that is exposed as a key of the same name on the global Metalsmith metadata.
You can omit passing any options to the plugin when matching based on a collection property.
Adds a path property to the collection item's data which contains the file path of the generated file. For example, this can be used in mustache templates to create links:
<h1><a href="/{{ path }}">{{ title }}</a></h1>
Additional metadata can be added to the collection object.
metalsmith.use(collections({
articles: {
sortBy: 'date',
reverse: true,
metadata: {
name: 'Articles',
description: 'The Articles listed here...'
}
}
}));
Collection metadata can also be assigned from a json or yaml file.
metalsmith.use(collections({
articles: {
sortBy: 'date',
reverse: true,
metadata: 'path/to/file.json'
}
}));
On each collection definition, it's possible to add a limit option so that the
collection length is not higher than the given limit:
metalsmith.use(collections({
lastArticles: {
sortBy: 'date',
limit: 10
}
}));
By adding refer: false to your options, it will skip adding the "next" and
"previous" links to your articles.
metalsmith.use(collections({
articles: {
refer: false
}
}));
All of the same options apply, just add them to the "plugins" key in your metalsmith.json configuration:
{
"plugins": {
"metalsmith-collections": {
"articles": {
"sortBy": "date",
"reverse": true
}
}
}
}
MIT
FAQs
A Metalsmith plugin that adds collections of files to the global metadata.
The npm package metalsmith-collections receives a total of 2,138 weekly downloads. As such, metalsmith-collections popularity was classified as popular.
We found that metalsmith-collections demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.