Added processing of alt text
parent
b06bc33b21
commit
90abf84693
15
build.js
15
build.js
|
@ -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",
|
||||
|
@ -18,7 +18,7 @@ files.forEach( file => {
|
|||
});
|
||||
|
||||
const re_include = new RegExp('{% include \'*(.*)\' %}');
|
||||
const re_picture = new RegExp('{% picture \'*(.*)\' %}');
|
||||
const re_picture = new RegExp('{% picture.*%}');
|
||||
|
||||
rl.on('line', line => {
|
||||
const match_include = line.match(re_include);
|
||||
|
@ -27,18 +27,21 @@ files.forEach( file => {
|
|||
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/.
|
||||
ensureDirectoryExists(build_dir + '/' + file.split('/').slice(1).join('/'));
|
||||
fs.writeFileSync(build_dir + '/' + file.split('/').slice(1).join('/'), file_buffer, 'utf8');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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>I’m Jordan Hanrahan — a Melbourne based art director and multi−disciplinary designer.</h2>
|
||||
|
|
Loading…
Reference in New Issue