]> git.r.bdr.sh - rbdr/blog/blame_incremental - lib/generators/html.js
Use serde and time
[rbdr/blog] / lib / generators / html.js
... / ...
CommitLineData
1import Dot from 'dot';
2import { readFile, writeFile } from 'fs/promises';
3import { join } from 'path';
4import { debuglog } from 'util';
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 */
20export default async function HTMLGenerator(source, target, posts) {
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');
30 const indexHtml = Dot.template(indexTemplate, {
31 ...Dot.templateSettings,
32 strip: false
33 })({ posts });
34 await writeFile(indexTarget, indexHtml);
35}