Verified Commit 9ac2bb48 authored by Aral Balkan's avatar Aral Balkan
Browse files

Build script is functional again for the new site

parent 9080e311
......@@ -10,7 +10,27 @@ const fs = require('fs')
let index = fs.readFileSync('index.html', 'utf-8')
const styles = fs.readFileSync('tmp/styles.css', 'utf-8')
const scripts = fs.readFileSync('tmp/scripts.js', 'utf-8')
// Note: the odd-looking replace is necessary because, after 24 years of using JavaScript, I just discovered
// ===== that string.replace is actually broken. Its default behaviour is to use dollar-denoted patterns in
// the replacement script to affect replacement behaviour. Until now, I was not bitten by this. What it
// means is, if you’re loading in content you don’t necessarily control and it has the dollar-denoted
// patterns in it, your replacement will not work as you thought it would. In this case, it broke on:
//
// const $ = document.querySelector.bind(document)
// const $$ = document.querySelectorAll.bind(document)
//
// The code after the replacement (without the hack below) would read:
//
// const $ = document.querySelector.bind(document)
// const $ = document.querySelectorAll.bind(document)
//
// This, of course, would then throw a JavaScript error.
//
// The way replace() should be designed is to default to not using patterns in the replacement string
// unless specifically told to do so.
//
const scripts = fs.readFileSync('tmp/scripts.js', 'utf-8').replace(/\$/g, '$$$$')
index = index.replace(/<\!-- Start: styles -->.*?<\!-- End: styles -->/s, `<style>${styles}</style>`)
index = index.replace(/<\!-- Start: scripts -->.*?<\!-- End: scripts -->/s, `<script>${scripts}</script>`)
......
......@@ -13,8 +13,6 @@ const fs = require('fs')
let index = fs.readFileSync('../tmp/index-minified.html', 'utf8')
console.log(index)
const emoji = fs.readdirSync('../images/emoji').map(f => `../images/emoji/${f}`)
const illustrations = fs.readdirSync('../images/illustrations').map(f => `/images/illustrations/${f}`)
......
......@@ -12,10 +12,12 @@ mkdir dist
# CSS (temporary; to be collated into index later).
echo " > Minify CSS"
minify css/highlight.js/github.css >> tmp/styles.css
minify css/index.css >> tmp/styles.css
# JS (temporary; to be collated into index later).
echo " > Minify JS"
minify js/highlight.pack.js >> tmp/scripts.js
minify js/index.js >> tmp/scripts.js
# Inline the CSS and JS into the HTML.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment