Render a folder of yaml files to html, recursively.
This is a fork from yaml-markdown-to-html. Git repo at mattermachine/yaml-to-html. To maintain this module:
- pull the repo
- edit
- up version in
package.json
- run
npm publish
to push to Artifactory - up the version accordingly in other modules that use this one.
To change documentation formatting, just change the render.js
script in the host repo. No need to edit this repo.
The command line interface accepts three folders:
# build
yaml-to-html <yaml> <html> <transform>
# watch
yaml-to-html --watch <yaml> <html> <transform>
<yaml>
is the source folder that contains the yaml files to render. <html>
is the destination folder that will contain the rendered html files. <transform>
is the folder, which contains at least a render.js
and may contain a post-render.js
, as well as other files that are used to render the yaml files to html. By default the CLI will look for a folder with the same name as the argument if omitted.
transform/render.js
is called once per file and gets an object with its parsed meta data and the raw markdown string, a collection of all other files in the current directory plus index pages of folders in the current directory and a collection of all files. It should return a Promise that fulfills with the rendered HTML.
example: transform/render.js
module.exports = function(currentFile, filesInCurrentFolder, allFiles) {
return Promise.resolve(
'<code>'
+JSON.stringify(currentFile, null, 2)+' of '+allFiles.length
+'\n'
+JSON.stringify(filesInCurrentFolder, null, 2)
+'</code>'
);
};
transform/postRender.js
receives a collection of rendered files including a renderedPath
property after all files have been rendered and should return a Promise that fulfills whenever it is done.
example: transform/post-render.js
module.exports = function postRender(renderedFiles) {
console.log('number of rendered files: %i', renderedFiles.length);
return Promise.resolve(renderedFiles);
};
The MIT License (MIT) Maximilian Hoffmann