Last active
March 13, 2023 08:49
-
-
Save hadrianw/060944011acfcadd889d937b960a5a1f to your computer and use it in GitHub Desktop.
NIH syndrome induced SSG.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
VERSION="siteprep-1" | |
EXT=".html" | |
HEAD='<!DOCTYPE html> | |
<meta charset=utf-8> | |
<meta name=viewport content="width=device-width,initial-scale=1"> | |
<style> | |
body{ | |
font:menu;font-size:1.125em; | |
margin:auto;max-width:40em; | |
padding:0 0.5em 90vh 0.5em; | |
} | |
</style>' | |
compile() { | |
local src="$1" | |
local dst="$2" | |
{ echo "$HEAD"; cat "$src"; } > "$dst" | |
} | |
gen_index() { | |
} | |
if test "$#" -eq 1; then | |
SRCDIR="." | |
DSTDIR="$1" | |
elif test "$#" -eq 2; then | |
SRCDIR="$1" | |
DSTDIR="$2" | |
elif test "$#" -eq 3; then | |
SRCDIR="$1" | |
DSTDIR="$2" | |
SRCFILE="$3" | |
DSTFILE="${SRCFILE%$EXT}.html" | |
DSTDIRFILE="$DSTDIR/$DSTFILE" | |
SRCDIRFILE="$SRCDIR/$SRCFILE" | |
if test ! -e "$DSTDIRFILE"; then | |
mkdir -p $(dirname "$DSTDIRFILE") | |
elif test "$SRCDIRFILE" -ot "$DSTDIRFILE"; then | |
echo "$DSTFILE" | |
exit 0 | |
fi | |
compile "$SRCDIRFILE" "$DSTDIRFILE" | |
echo "$DSTFILE" | |
exit 0 | |
else | |
echo "usage: ./siteprep.sh [srcdir] dstdir" > /dev/stderr | |
exit 1 | |
fi | |
mkdir -p "$DSTDIR" | |
echo "$VERSION" > "$DSTDIR/build-info.new" | |
OLD_VERSION="$(head -n1 "$DSTDIR/build-info")" | |
if test "$VERSION" != "$OLD_VERSION"; then | |
# force rebuild if a different version | |
mv "$DSTDIR/build-info" "$DSTDIR/build-info.old" | |
fi | |
if test ! -e "$DSTDIR/build-info"; then | |
touch "$DSTDIR/build-info" | |
fi | |
# for every found source file in srcdir: | |
# * pass it to gen_index and | |
# * compile the file, which will pass further the dst file name | |
# sort and save the new build-info file | |
# compare old build-info to new build-info as it is written | |
# remove files missing from new build-info | |
# FIXME: remove empty direcotries | |
comm -23 <(awk 'NR>1' "$DSTDIR/build-info") <(find "$SRCDIR" -name "*$EXT" -type f -printf "%P\n" | tee >(gen_index) | xargs -n1 "$0" "$SRCDIR" "$DSTDIR" | sort | tee -a "$DSTDIR/build-info.new") | (cd "$DSTDIR" && xargs rm) | |
mv "$DSTDIR"/build-info{.new,} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment