posthtml-include-whatever
v0.0.1
Published
A generic <include> processor for posthtml
Readme
posthtml-include-whatever
Include anything plugin for PostHTML. Based on posthtml-include
Install
$ npm install posthtml-include-whatever
$ # OR
$ yarn add posthtml-include-whateverUsage
const { readFileSync } = require('fs')
const posthtml = require('posthtml')
const whatever = require('posthtml-include-whatever')
const renderers = {
markdown: (filePath, { encoding }) => {
// process markdown and return string
},
handlebars: (filePath, { locals, encoding }) => {
// process handlebars and return string
},
// etc
}
const html = readFileSync('index.html')
posthtml([ whatever({ renderers, encoding: 'utf8', locals: {} }) ])
.process(html)
.then((result) => console.log(result.html))In the HTML:
<html>
<head>
<title>index.html</title>
</head>
<body>
<include src="posts/hello.md" type="markdown"></include>
<include src="posts/footer.handlebars" type="handlebars"></include>
</body>
</html>Configuration
root: Root folder path for include. Default./encoding: Defaultutf-8renderers: Object mapping include type names to a render function that accepts a filepath argument, and an options argument containingencodingandlocals
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am "Add some feature" - Push to the branch:
git push origin my-new-feature - Submit a pull request
License
MIT
