]>
git.r.bdr.sh - rbdr/blog/blob - lib/generators/html.js
ba2676cdb60c62ade486ce1b644dd2b7f37a3e10
3 const { template
} = require('dot');
4 const { readFile
, writeFile
} = require('fs/promises');
5 const { join
} = require('path');
6 const { debuglog
} = require('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 module
.exports
= 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
= template(indexTemplate
)({ posts
});
33 await
writeFile(indexTarget
, indexHtml
);