]> git.r.bdr.sh - rbdr/blog/blame - lib/generators/html.js
Update README.md
[rbdr/blog] / lib / generators / html.js
CommitLineData
6cd62e79
RBR
1import Dot from 'dot';
2import { readFile, writeFile } from 'fs/promises';
3import { join } from 'path';
4import { debuglog } from 'util';
67fdfa7c
BB
5
6const internals = {
7 debuglog: debuglog('blog'),
8
9 kIndexName: 'index.html'
10};
11
12/**
13 * Generates the blog index page
14 *
15 * @name HTMLGenerator
16 * @param {string} source the source directory
17 * @param {string} target the target directory
18 * @param {Array.<Blog.tPost>} posts the list of posts
19 */
6cd62e79 20export default async function HTMLGenerator(source, target, posts) {
67fdfa7c
BB
21
22 internals.debuglog('Generating HTML');
23 const indexTarget = join(target, internals.kIndexName);
24 const indexLocation = join(source, internals.kIndexName);
25
26 internals.debuglog(`Reading ${indexLocation}`);
27 const indexTemplate = await readFile(indexLocation, { encoding: 'utf8' });
28
29 internals.debuglog('Writing HTML');
6cd62e79
RBR
30 const indexHtml = Dot.template(indexTemplate, {
31 ...Dot.templateSettings,
9e355758
RBR
32 strip: false
33 })({ posts });
67fdfa7c 34 await writeFile(indexTarget, indexHtml);
10a76a5b 35}