]>
git.r.bdr.sh - rbdr/blog/blob - lib/generators/static.js
4713ea7dca51c841fcd695d46c1a377c1643b714
3 const { access
, rm
} = require('fs/promises');
4 const { ncp
} = require('ncp');
5 const { join
} = require('path');
6 const { debuglog
, promisify
} = require('util');
10 debuglog: debuglog('blog'),
12 kAssetsDirectoryName: 'assets'
16 * Generates the static assets required for the blog
18 * @name StaticGenerator
19 * @param {string} source the source directory
20 * @param {string} target the target directory
21 * @param {Array.<Blog.tPost>} posts the list of posts
23 module
.exports
= async
function StaticGenerator(source
, target
, posts
) {
25 const assetsTarget
= join(target
, internals
.kAssetsDirectoryName
);
27 internals
.debuglog(`Removing ${assetsTarget}`);
28 await
rm(assetsTarget
, { recursive: true, force: true });
30 for (let i
= 0; i
< posts
.length
; ++i
) {
31 const postSourcePath
= join(source
, `${i}`);
34 await
access(postSourcePath
);
36 const assetsSource
= join(postSourcePath
, internals
.kAssetsDirectoryName
);
38 internals
.debuglog(`Copying ${assetsSource} to ${assetsTarget}`);
39 await internals
.ncp(assetsSource
, assetsTarget
);
42 if (error
.code
=== internals
.kFileNotFoundError
) {
43 internals
.debuglog(`Skipping ${i}`);