A Metalsmith plugin to render strings within frontmatter.
You could have used metalsmith-frontmatter-file-loader to get those strings from seperate files.
$ npm install metalsmith-frontmatter-renderer
Note: you will need to install the jstranformer that you want to use. No transformers are required as dependencies of this package.
e.g. to use the default markdown transformer you will need to also run
$ npm install jstransformer-markdown
You can pass some basic options to customize the behaviour:
keyis the key of the object to iterate over in the files frontmatter. Default
outis the key of the object to update the values upon. Default the value of
extis a string used by inputformat-to-jstransformer to determine which jstransformer to load and use. Note: you do need to install whichever jstransformer you want to use. Default
suppressNoFilesErroris a boolean to determine the behaviour when there are no files to look check the frontmatter of. Set to
trueto prevent an error being thrown if there are no files. Default
optionsis an object that will be passed to the jstransformer render function as the second parameter (options). Default to empty object
Install via npm and then add the
metalsmith-frontmatter-renderer key to your
or with configuration options:
options to the plugin and pass it to Metalsmith with the
var fmfl = ;metalsmith;
——— files: foo: '# Here is some *markdown*' bar: '`blocks` will be rendered using a [jstranformer](https://github.com/jstransformers/jstransformer)' ——— <h1>This is the <code>contents</code> of the file.</h1>
By default this would render the two properties
bar using the markdown jstransformer.
It would replace the contents of those two properties with the rendered string.
e.g this is the equivalent of having written out the rendered contents into the frontmatter as so:
——— files: foo: '<h1>Here is some <em>markdown</em></h1>' bar: '<p><code>blocks</code> will be rendered using a <a href="https://github.com/jstransformers/jstransformer">jstranformer</a></p>' ——— <h1>This is the <code>contents</code> of the file.</h1>
If you use a property other than
blocks then you can pass the name as a configuration option. See the config documentation above.