#!/bin/sh #umask 0113 dir="$(echo "$0"|sed 's|/[^/]\+$||')" if [ -d "$dir" ];then cd "$dir";fi header="inc/header.html" footer_start="inc/footer_start.html" footer_end="inc/footer_end.html" mdate(){ date="$(date -u -d "@$(stat -c %Y "$1" )" "+%Y-%m-%dT%H:%MZ")" printf "%s\n" "${2:-Last Modified: }" "$date" "$(echo "$date"|sed 's/T/ /;s/Z/ UTC/')" } # no_ext removes the trailing .html, # useful to tidy the URL, if you've set up your server to work with that in mind #server-specific checks to enable stripping suffixes ONLY on system html path, on tilde.cafe if [ "$(hostname --fqdn)" = "tilde.cafe" ] && [ "$(readlink -f "$dir"|head -c 4)" = "/var" ];then no_ext=1 #if on webroot, try to ignore any discrepancies and use upstream echo "updating repo" git stash;git stash clear git pull git submodule update --remote --rebase --single-branch --recommend-shallow else no_ext=0 fi TZ=UTC date echo "generating site" #. in reference to src/ for path in . ./wiki;do tmpindex=$(mktemp --suffix '.md') # for generating list of markdown links for index.html path="src/$path" cat "$path/index.md" > $tmpindex dir="$(echo $path|cut -d / -f 2-)"; # find "$path" -maxdepth 1 -name "*.md" -exec sh -c "dir=\"$dir\" tmpindex=\"$tmpindex\""' find "$path" -maxdepth 1 -name "*.md"|while read filename;do # filename="$(basename "{}"|rev|cut -d . -f 2-|rev)"; filename="$(basename "$filename"|rev|cut -d . -f 2-|rev)"; #skip parsing the readme file, case insensitive if [ "$(basename "$(echo "$filename"|tr [:upper:] [:lower:])"|rev|cut -d . -f 2-|rev)" = "readme" ];then echo "skipping $filename" continue #skip the file fi if [ "$dir" = "." ] && [ "$filename" = "index" ];then continue;fi if (echo "$dir" | grep "wiki") >/dev/null && (echo "$filename"|grep -v "^index$") >/dev/null;then echo "- [$filename]($filename.html)" >> $tmpindex fi echo "building dist/$dir/$filename.html"; mkdir -p "dist/$dir/" && touch "dist/$dir/$filename.html"; markdown "src/$dir/$filename.md" | if [ "$no_ext" = "1" ];then sed -e 's|\(|\1">|g'\ -e 's|\(|\1">|g' else cat fi | cat "$header" - "$footer_start" >"dist/$dir/$filename.html" mdate "src/$dir/$filename.md"| cat - "$footer_end" >>"dist/$dir/$filename.html" # ' \; done done echo "creating user list page.." ./users.sh|markdown| if [ "$no_ext" = "1" ];then sed -e 's|\(|\1\2">|g' else cat;fi | cat "$header" - "$footer_start" > dist/users.html mdate "dist/users.html" "Last Generated: "| cat - "$footer_end" >> dist/users.html echo "creating index page.." ./users.sh| cat src/index.md -|markdown| if [ "$no_ext" = "1" ];then sed -e 's|\(|\1\2">|g' else cat;fi | cat "$header" - "$footer_start" > dist/index.html mdate "dist/index.html" "Last Generated: "| cat - "$footer_end" >> dist/index.html echo "creating index page for wiki..." markdown "$tmpindex" | if [ "$no_ext" = "1" ];then sed -e 's|\(|\1">|g'\ -e 's|\(|\1">|g' else cat fi | cat "$header" - "$footer_start" > dist/wiki/index.html mdate "dist/wiki/index.html" "Last Generated: "| cat - "$footer_end" >> dist/wiki/index.html rm "$tmpindex" echo "all done!" # rsync (flags to delete if src is deleted) dist/ /var/www/tilde.cafe/