2023-05-21 11:59:27 +00:00
|
|
|
const fs = require('fs');
|
2023-05-25 10:40:32 +00:00
|
|
|
const readline = require('readline');
|
|
|
|
//const src_dir = 'src';
|
|
|
|
const build_dir = 'build';
|
2023-05-21 11:59:27 +00:00
|
|
|
|
2023-05-23 13:31:23 +00:00
|
|
|
const files = ["src/index.html",
|
2023-05-25 10:30:42 +00:00
|
|
|
"src/about.html",
|
|
|
|
"src/projects/2016-XXXX.html",
|
|
|
|
"src/projects/2023-Pepperstone.html"]; // this list should be generated.
|
2023-05-23 13:31:23 +00:00
|
|
|
|
|
|
|
files.forEach( file => {
|
|
|
|
var file_buffer = "";
|
|
|
|
|
|
|
|
const rl = readline.createInterface({
|
2023-05-25 10:30:42 +00:00
|
|
|
input: fs.createReadStream(file),
|
|
|
|
output: process.stdout,
|
|
|
|
terminal: false
|
2023-05-23 13:31:23 +00:00
|
|
|
});
|
|
|
|
|
2023-05-25 10:30:42 +00:00
|
|
|
const re_include = new RegExp('{% include \'*(.*)\' %}');
|
|
|
|
const re_picture = new RegExp('{% picture \'*(.*)\' %}');
|
2023-05-23 13:31:23 +00:00
|
|
|
|
|
|
|
rl.on('line', line => {
|
2023-05-25 10:30:42 +00:00
|
|
|
const match_include = line.match(re_include);
|
|
|
|
const match_picture = line.match(re_picture);
|
|
|
|
if (match_include) {
|
|
|
|
line = line.replace(re_include, fs.readFileSync(match_include[1], 'utf8'));
|
|
|
|
}
|
|
|
|
if (match_picture) {
|
|
|
|
const picture_src = match_picture[1].split('/').slice(1).join('/');
|
2023-05-25 10:40:32 +00:00
|
|
|
ensureDirectoryExists(build_dir + '/' + picture_src);
|
|
|
|
fs.cp(match_picture[1], build_dir + '/' + picture_src, { recursive: false }, (err) => {
|
2023-05-25 10:30:42 +00:00
|
|
|
if (err) throw err;
|
|
|
|
});
|
|
|
|
line = line.replace(re_picture, "<img src=\'/" + picture_src + "\' \>");
|
|
|
|
}
|
|
|
|
file_buffer += line;
|
2023-05-23 13:31:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
rl.on('close', () => {
|
2023-05-25 10:40:32 +00:00
|
|
|
ensureDirectoryExists(build_dir + '/' + file.split('/').slice(1).join('/')); // all this quatch is to remove the /src/.
|
|
|
|
fs.writeFileSync(build_dir + '/' + file.split('/').slice(1).join('/'), file_buffer, 'utf8');
|
2023-05-23 13:31:23 +00:00
|
|
|
});
|
2023-05-21 11:59:27 +00:00
|
|
|
});
|
2023-05-23 13:31:23 +00:00
|
|
|
|
|
|
|
fs.cp('./src/styles','./build/styles', { recursive: true }, (err) => {
|
|
|
|
if (err) throw err;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function ensureDirectoryExists(filePath) {
|
|
|
|
var dirname = filePath.split('/').slice(0,-1).join('/');
|
|
|
|
if (fs.existsSync(dirname)) {
|
2023-05-25 10:30:42 +00:00
|
|
|
return true;
|
2023-05-23 13:31:23 +00:00
|
|
|
}
|
|
|
|
ensureDirectoryExists(dirname);
|
|
|
|
fs.mkdirSync(dirname);
|
|
|
|
}
|