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