| d239f085 Andy McCall ↶ |
1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
set -eu |
| 9 |
cd "$(dirname "$0")/.." |
| 10 |
rm -rf public |
| 11 |
mkdir -p public |
| 12 |
(cd src && find . -type f) | while read -r f; do |
| 13 |
mkdir -p "public/$(dirname "$f")" |
| 14 |
case "$f" in |
| 15 |
*.html) |
| 16 |
awk ' |
| 17 |
/<!-- include header -->/ { while ((getline l < "partials/header.html") > 0) print l; close("partials/header.html"); next } |
| 18 |
/<!-- include footer -->/ { while ((getline l < "partials/footer.html") > 0) print l; close("partials/footer.html"); next } |
| 19 |
{ print } |
| 20 |
' "src/$f" > "public/$f" |
| 21 |
if grep -q '<!-- include ' "public/$f"; then |
| 22 |
echo "build: $f names a partial that does not exist" >&2 |
| 23 |
exit 1 |
| 24 |
fi |
| 25 |
;; |
| 26 |
*) cp "src/$f" "public/$f" ;; |
| 27 |
esac |
| 28 |
done |
| 29 |
|
| 30 |
|
| 31 |
if grep -rniE 'src="(https?:)?//|<link[^>]*href="(https?:)?//' public --include='*.html'; then |
| 32 |
echo "build: a page loads a resource from another site (above)" >&2 |
| 33 |
exit 1 |
| 34 |
fi |
| 35 |
if grep -rniE 'url\((https?:)?//|@import' public --include='*.css'; then |
| 36 |
echo "build: the stylesheet loads something from another site (above)" >&2 |
| 37 |
exit 1 |
| 38 |
fi |
| 39 |
tar -C public -czf site.tar.gz . |
| 40 |
echo "built $(find public -type f | wc -l) files into public/ and site.tar.gz" |