Added processing of alt text

trunk
Jordan Hanrahan 2023-05-26 12:17:34 +10:00
parent b06bc33b21
commit 90abf84693
2 changed files with 18 additions and 15 deletions

View File

@ -1,6 +1,6 @@
const fs = require('fs');
const readline = require('readline');
//const src_dir = 'src';
const src_dir = 'src';
const build_dir = 'build';
const files = ["src/index.html",
@ -9,36 +9,39 @@ const files = ["src/index.html",
"src/projects/2023-Pepperstone.html"]; // this list should be generated.
files.forEach( file => {
var file_buffer = "";
var file_buffer = "";
const rl = readline.createInterface({
const rl = readline.createInterface({
input: fs.createReadStream(file),
output: process.stdout,
terminal: false
});
});
const re_include = new RegExp('{% include \'*(.*)\' %}');
const re_picture = new RegExp('{% picture \'*(.*)\' %}');
const re_include = new RegExp('{% include \'*(.*)\' %}');
const re_picture = new RegExp('{% picture.*%}');
rl.on('line', line => {
rl.on('line', line => {
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('/');
const re_src = new RegExp("src=[\'\"](.*?)[\'\"]");
const picture_src = match_picture[0].match(re_src)[1].split('/').slice(1).join('/');
const re_alt = new RegExp("alt=[\'\"](.*?)[\'\"]");
const alt = match_picture[0].match(re_alt)[1];
ensureDirectoryExists(build_dir + '/' + picture_src);
fs.cp(match_picture[1], build_dir + '/' + picture_src, { recursive: false }, (err) => {
fs.cp(src_dir + '/' + picture_src, build_dir + '/' + picture_src, { recursive: false }, (err) => {
if (err) throw err;
});
line = line.replace(re_picture, "<img src=\'/" + picture_src + "\' \>");
line = line.replace(re_picture, "<img src=\'/" + picture_src + "\' alt=\'" + alt + "\' \>");
}
file_buffer += line;
});
rl.on('close', () => {
ensureDirectoryExists(build_dir + '/' + file.split('/').slice(1).join('/')); // all this quatch is to remove the /src/.
});
rl.on('close', () => {
ensureDirectoryExists(build_dir + '/' + file.split('/').slice(1).join('/'));
fs.writeFileSync(build_dir + '/' + file.split('/').slice(1).join('/'), file_buffer, 'utf8');
});
});

View File

@ -2,7 +2,7 @@
{% include 'src/components/header.html' %}
<main>
<div>
{% picture 'src/images/JHN_Head_200131_v03.png' %}
{% picture src='src/images/JHN_Head_200131_v03.png' alt='Face line-drawing' %}
</div>
<div>
<h2>Im Jordan Hanrahan — a&nbspMelbourne based art director and multidisciplinary designer.</h2>