1.1.0 • Published 2 years ago
@sphido/nunjucks v1.1.0
@sphido/nunjucks
This package allow use nunjucks - a rich and powerful templating language for JavaScript from Mozilla for rendering HTML files from page object.
Functions:
env.addFilter(name, func, [async])
- allow addFilter to nunjucks template engine.nunjucks.render(name, [context], [callback])
- render the template see nunjucks docsnunjucks.renderString(str, context, [callback])
-renderToFile(file, template, vars = undefined)
- render the template to file
Extenders:
save(dir, template = 'theme/page.html')
- function extender allow save page to file
Install
yarn add @sphido/nunjucks
Usage
import globby from 'globby';
import {save} from '@sphido/nunjucks';
import {getPages} from '@sphido/core';
import {frontmatter} from '@sphido/frontmatter';
import {markdown} from '@sphido/markdown';
import {meta} from '@sphido/meta';
(async () => {
// 1. get list of pages...
const posts = await getPages(
await globby('content/**/*.md'),
...[
frontmatter,
markdown,
meta,
{save}
],
);
// 2. save to html with default template
for await (const page of posts) {
page.save(
page.dir.replace('content', 'public')
);
}
})();
Source codes
https://github.com/sphido/sphido/tree/main/packages/sphido-nunjucks
1.1.0
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago