the optimizer
This commit is contained in:
parent
b20f843c47
commit
ab5c46d14f
9
Makefile
9
Makefile
|
@ -1,9 +0,0 @@
|
|||
testing:
|
||||
./build.sh build
|
||||
|
||||
clean:
|
||||
./build.sh clean
|
||||
|
||||
server:
|
||||
./build.sh -o ~/public/www clean
|
||||
./build.sh -o ~/public/www build
|
59
build.sh
59
build.sh
|
@ -18,44 +18,39 @@ cleanup() {
|
|||
# if a second argument is given, that is the output file
|
||||
# otherwise, the output file is $BUILDDIR/<filepath>
|
||||
process_html() {
|
||||
inter="$(mktemp)"
|
||||
tmp="$(mktemp)"
|
||||
|
||||
[ -n "${2:-}" ] && outfile="$2" || outfile="$1"
|
||||
# only one use of grep to be efficient
|
||||
i="$(grep -Ece '<!--sh[[:space:]]+' "$1")"
|
||||
|
||||
while grep -q -E -e '<!--sh[[:space:]]*' "$1"; do
|
||||
sh -s > "$inter" <<-EOF
|
||||
$(awk -v FS='<!--sh[[:space:]]+' -v RS='[[:space:]]+-->' \
|
||||
'NF > 1 {print $NF; exit}' "$1")
|
||||
EOF
|
||||
# can this be made smaller?
|
||||
# the goal is to replace all text between
|
||||
# <!--sh and --> with the contents of another file
|
||||
# minus the newline at the end
|
||||
awk -v repfile="$inter" '
|
||||
BEGIN {
|
||||
while (getline var < repfile) {
|
||||
a[i++] = var
|
||||
while [ $i -gt 0 ]; do
|
||||
awk -v FS='<!--sh[[:space:]]+' -v RS='[[:space:]]+-->' \
|
||||
'NF > 1 {print $NF; exit}' "$1" \
|
||||
| sh -s | \
|
||||
awk '
|
||||
BEGIN {
|
||||
RS="\a"
|
||||
getline var
|
||||
RS="<!--sh[[:space:]]+"
|
||||
FS="[[:space:]]+-->"
|
||||
OFS=" -->"
|
||||
ORS=""
|
||||
}
|
||||
close(repfile)
|
||||
FS="<!--sh[[:space:]]+"
|
||||
RS="[[:space:]]+-->"
|
||||
ORS=""
|
||||
}
|
||||
|
||||
NF > 1 && NR == 1 {
|
||||
print $1
|
||||
for (n=0; n < (i - 1); n++) {
|
||||
print a[n] "\n"
|
||||
|
||||
FNR == 2 {
|
||||
printf substr(var, 1, length(var)-1)
|
||||
for (i = 2; i < NF; i++)
|
||||
print $i " -->"
|
||||
print $i
|
||||
RS="\a"
|
||||
}
|
||||
print a[n]
|
||||
FS=" "
|
||||
RS=ORS="\n"
|
||||
}
|
||||
|
||||
FNR == 1
|
||||
FNR > 2 { print "<!--sh " $0 }
|
||||
' - "$1" > "$tmp"
|
||||
|
||||
NR > 1 { print $0 }' "$1" > "$tmp"
|
||||
|
||||
mv "$tmp" "$outfile"
|
||||
mv -f "$tmp" "$1"
|
||||
i=$((i-1))
|
||||
done
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue