A metalsmith plugin to write the metadata excerpted from the files to the filesystem as json files.
$ npm install metalsmith-writemetadata
var writemetadata = require('metalsmith-writemetadata');
Metalsmith(__dirname)
.use(writemetadata());
Metalsmith(__dirname)
.use(writemetadata({
pattern: ['*.md', '*.html']
}));
Accepts as paramater a pattern like in multimatch.
Metalsmith(__dirname)
.use(writemetadata({
ignorekeys: ['next', 'previous']
}));
Accepts an array of keys to ignore in the output.
If used together with the collections plugin, this plugin can also write collections.
Metalsmith(__dirname)
.use(collections({
projects: {
pattern: 'content/projects/*.html'
}
}))
.use(writemetadata({
collections: {
projects: {
output: {
path: 'content/projects.json',
asObject: true,
metadata: {
"type": "list"
}
},
ignorekeys: ['contents', 'next', 'previous']
}
}
}))
output is a parameter for collections, determining the desired output. If asObject is false, an array will be output. Otherwise a object in following format (taking example from above):
{
name: 'projects',
total: 9,
type: 'list',
result: [...]
}
This example is from a real world example:
Metalsmith(__dirname)
.source('./resources')
.destination('./build')
.use(ignore([
'**/.bower.json',
'**/*.gzip'
]))
.use(markdown())
.use(collections({
projects: {
pattern: 'content/projects/*.html'
}
}))
.use(writemetadata({
pattern: ['**/*.html'],
ignorekeys: ['next', 'previous'],
collections: {
projects: {
output: {
path: 'content/projects.json',
asObject: true,
metadata: {
"type": "list"
}
},
ignorekeys: ['contents', 'next', 'previous']
}
}
}))
MIT