]> git.r.bdr.sh - rbdr/blog/blame - lib/generators/txt.js
Lint
[rbdr/blog] / lib / generators / txt.js
CommitLineData
6cd62e79
RBR
1import Dot from 'dot';
2import { readFile, writeFile } from 'fs/promises';
3import { join } from 'path';
4import { debuglog } from 'util';
5f31ea34
BB
5
6const internals = {
7 debuglog: debuglog('blog'),
8
9 kTextName: 'index.txt'
10};
11
12/**
13 * Generates a TXT version of the blog
14 *
15 * @name TXTGenerator
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 */
6cd62e79 20export default async function TXTGenerator(source, target, posts) {
5f31ea34
BB
21
22 internals.debuglog('Generating TXT');
23 const textTarget = join(target, internals.kTextName);
24 const textLocation = join(source, internals.kTextName);
25
26 internals.debuglog(`Reading ${textLocation}`);
27 const textTemplate = await readFile(textLocation, { encoding: 'utf8' });
28
29 internals.debuglog('Writing TXT');
6cd62e79
RBR
30 const text = Dot.template(textTemplate, {
31 ...Dot.templateSettings,
5f31ea34
BB
32 strip: false
33 })({ posts });
34 await writeFile(textTarget, text);
10a76a5b 35}