]>
git.r.bdr.sh - rbdr/blog/blob - lib/generators/html.js
f7c7966b08da7af556377a04954de87898ee1847
4 import { readFile
, writeFile
} from 'fs/promises';
5 import { join
} from 'path';
6 import { debuglog
} from 'util';
9 debuglog: debuglog('blog'),
11 kIndexName: 'index.html'
15 * Generates the blog index page
18 * @param {string} source the source directory
19 * @param {string} target the target directory
20 * @param {Array.<Blog.tPost>} posts the list of posts
22 export default async
function HTMLGenerator(source
, target
, posts
) {
24 internals
.debuglog('Generating HTML');
25 const indexTarget
= join(target
, internals
.kIndexName
);
26 const indexLocation
= join(source
, internals
.kIndexName
);
28 internals
.debuglog(`Reading ${indexLocation}`);
29 const indexTemplate
= await
readFile(indexLocation
, { encoding: 'utf8' });
31 internals
.debuglog('Writing HTML');
32 const indexHtml
= Dot
.template(indexTemplate
, {
33 ...Dot
.templateSettings
,
36 await
writeFile(indexTarget
, indexHtml
);