Added processing of alt text
parent
b06bc33b21
commit
90abf84693
29
build.js
29
build.js
|
@ -1,6 +1,6 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const readline = require('readline');
|
const readline = require('readline');
|
||||||
//const src_dir = 'src';
|
const src_dir = 'src';
|
||||||
const build_dir = 'build';
|
const build_dir = 'build';
|
||||||
|
|
||||||
const files = ["src/index.html",
|
const files = ["src/index.html",
|
||||||
|
@ -9,36 +9,39 @@ const files = ["src/index.html",
|
||||||
"src/projects/2023-Pepperstone.html"]; // this list should be generated.
|
"src/projects/2023-Pepperstone.html"]; // this list should be generated.
|
||||||
|
|
||||||
files.forEach( file => {
|
files.forEach( file => {
|
||||||
var file_buffer = "";
|
var file_buffer = "";
|
||||||
|
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: fs.createReadStream(file),
|
input: fs.createReadStream(file),
|
||||||
output: process.stdout,
|
output: process.stdout,
|
||||||
terminal: false
|
terminal: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const re_include = new RegExp('{% include \'*(.*)\' %}');
|
const re_include = new RegExp('{% include \'*(.*)\' %}');
|
||||||
const re_picture = new RegExp('{% picture \'*(.*)\' %}');
|
const re_picture = new RegExp('{% picture.*%}');
|
||||||
|
|
||||||
rl.on('line', line => {
|
rl.on('line', line => {
|
||||||
const match_include = line.match(re_include);
|
const match_include = line.match(re_include);
|
||||||
const match_picture = line.match(re_picture);
|
const match_picture = line.match(re_picture);
|
||||||
if (match_include) {
|
if (match_include) {
|
||||||
line = line.replace(re_include, fs.readFileSync(match_include[1], 'utf8'));
|
line = line.replace(re_include, fs.readFileSync(match_include[1], 'utf8'));
|
||||||
}
|
}
|
||||||
if (match_picture) {
|
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);
|
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;
|
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;
|
file_buffer += line;
|
||||||
});
|
});
|
||||||
|
|
||||||
rl.on('close', () => {
|
rl.on('close', () => {
|
||||||
ensureDirectoryExists(build_dir + '/' + file.split('/').slice(1).join('/')); // all this quatch is to remove the /src/.
|
ensureDirectoryExists(build_dir + '/' + file.split('/').slice(1).join('/'));
|
||||||
fs.writeFileSync(build_dir + '/' + file.split('/').slice(1).join('/'), file_buffer, 'utf8');
|
fs.writeFileSync(build_dir + '/' + file.split('/').slice(1).join('/'), file_buffer, 'utf8');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% include 'src/components/header.html' %}
|
{% include 'src/components/header.html' %}
|
||||||
<main>
|
<main>
|
||||||
<div>
|
<div>
|
||||||
{% picture 'src/images/JHN_Head_200131_v03.png' %}
|
{% picture src='src/images/JHN_Head_200131_v03.png' alt='Face line-drawing' %}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h2>I’m Jordan Hanrahan — a Melbourne based art director and multi−disciplinary designer.</h2>
|
<h2>I’m Jordan Hanrahan — a Melbourne based art director and multi−disciplinary designer.</h2>
|
||||||
|
|
Loading…
Reference in New Issue