]>
git.r.bdr.sh - rbdr/blog/blob - lib/generators/html.js
20046962ce29416bd8b190c38ef4b71ff64552f2
2 import { readFile
, writeFile
} from 'fs/promises';
3 import { join
} from 'path';
4 import { debuglog
} from 'util';
7 debuglog: debuglog('blog'),
9 kIndexName: 'index.html'
13 * Generates the blog index page
16 * @param {string} source the source directory
17 * @param {string} target the target directory
18 * @param {Array.<Blog.tPost>} posts the list of posts
20 export default async
function HTMLGenerator(source
, target
, posts
) {
22 internals
.debuglog('Generating HTML');
23 const indexTarget
= join(target
, internals
.kIndexName
);
24 const indexLocation
= join(source
, internals
.kIndexName
);
26 internals
.debuglog(`Reading ${indexLocation}`);
27 const indexTemplate
= await
readFile(indexLocation
, { encoding: 'utf8' });
29 internals
.debuglog('Writing HTML');
30 const indexHtml
= Dot
.template(indexTemplate
, {
31 ...Dot
.templateSettings
,
34 await
writeFile(indexTarget
, indexHtml
);