metalsmith-map-permalinks
v1.0.0
Published
Generate permalinks and a map of source file path to permalink
Downloads
3
Readme
metalsmith-map-permalinks :link:
A Metalsmith plugin to generate permalinks and paths for files and store a mapping from input files to paths.
This plugin will generate a permalink for all files that match its pattern using
a list of formats. The formats are mustache
strings and are
evaluated first to last, so order matters. The values for the permalink fields
are taken from the file metadata. Here's an example using the JavaScript API:
import map_permalinks from 'metalsmith-map-permalinks'
Metalsmith(__dirname)
.source('src')
.destination('dst')
.use(map_permalinks({
formats: [
{
pattern: 'posts/*.md',
format: '{{date}}/{{title}}',
date_format: 'yyyy',
},
{
pattern: 'pages/*.md',
format: '{{title}}',
},
],
}))
Installation
From NPM:
$ npm install --save-dev metalsmith-map-permalinks
$ yarn add --dev metalsmith-map-permalinks
From GitHub:
$ npm install --save-dev https://github.com/ryanq/metalsmith-map-permalinks
$ yarn add --dev https://github.com/ryanq/metalsmith-map-permalinks
Options
Options for configuring metalsmith-map-permalinks
can be passed as an argument
to the plugin function for the JavaScript API or as the value of the
metalsmith-map-permalinks
key for the CLI. The options are:
pattern
: Only process files that match the pattern. The default is'**'
.key
: The key in the file metadata to use as the source string in the mapping. The default isundefined
formats
: An array of format objects to use. The default is adefault: true
format withformat: '{{title}}'
. Formats have the following options:pattern
: Only apply the format to files that matche the pattern.default
: This is the default format and will match against any filename.format
: The format for the permalink.date_format
: The format to use when{{date}}
is in the permalink.
Debugging
metalsmith-map-permalinks
uses the debug
package for logging during the
build. Enable logging by setting DEBUG to include map-permalinks
:
$ DEBUG=map-permalinks yarn build
yarn run v1.16.0
$ node build/index.mjs
map-permalinks processing file pages/about.md +0ms
map-permalinks using format {{title}} +1ms
map-permalinks generated permalink about +1ms
map-permalinks mapping about to /about/ +0ms
map-permalinks replacing pages/about.md with about/index.html +0ms
map-permalinks processing file posts/post-1.md +0ms
map-permalinks using format {{date}}/{{title}} +1ms
map-permalinks generated permalink 2018/post-1 +0ms
map-permalinks mapping learning-go to /2018/post-1/ +0ms
map-permalinks replacing posts/post-1.md with 2018/post-1/index.html +0ms
map-permalinks processing file posts/post-2.md +0ms
map-permalinks using format {{date}}/{{title}} +1ms
map-permalinks generated permalink 2019/post-2 +0ms
map-permalinks mapping post-2 to /2019/post-2/ +0ms
map-permalinks replacing posts/post-2.md with 2019/post-2/index.html +0ms
✨ Done in 1.30s.