OXYGENHUB
◆ main oxygenvcs-web / scripts / build.sh
1.7 KiB · Bourne Again Shell (bash) · executable · last changed The site: a static product page, built by OxygenFlow, pulled by its host (refs #1) 9 days ago source blame history raw
d239f085 Andy McCall ↶ 1
#!/bin/sh
2
# Build the site into public/ and pack it as site.tar.gz: each page in
3
# src/ has its `<!-- include header -->` and `<!-- include footer -->`
4
# lines replaced by partials/header.html and partials/footer.html;
5
# everything else in src/ is copied as it is. Plain sh, awk and tar, so
6
# it runs in any image (and on the VisionFive 2 Lite) with nothing to
7
# install.
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
# Nothing in the site may load from elsewhere (the footer promises it).
30
# Links out are fine; nothing a page loads (src=, <link href=) may be.
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"