#! /usr/bin/env bash source ./gmirator.conf COMMAND=$1 PARAM=$2 make_gemlogs_index() { rm articles.gmi.temp echo "generating articles.gmi.temp" ls $LGMI/gemlog | grep -v 'index' | sort -r \ | while read fname; do local date=$(echo "$fname" | sed "s/_.*//") local title=$(head -1 $LGMI/gemlog/$fname | sed "s/# //") echo "=> gemlog/$fname $date - $title" >> $WORKDIR/articles.gmi.temp done echo "generating gemlog/index.gmi" sed -i -e "/^## logs/,//{ /^#/!d }" -e "/^## logs/{ a r $WORKDIR/articles.gmi.temp }" $LGMI/gemlog/index.gmi echo "generating index.gmi" printf ' => tinylog.gmi tinylogs go here => gemlog/index.gmi full gemlogs here \n%s' "$(head $WORKDIR/articles.gmi.temp)" \ | cat $WORKDIR/in.gmi - > $LGMI/index.gmi echo "" >> $LGMI/index.gmi echo "DONE :)" } gmi2html() { local in_list=no local in_preformated=no while read -r line; do if [[ "$in_list" == yes ]]; then if [[ "$line" == '* '* ]]; then printf "
\n" ;; *) printf "%s
\n" "$line" ;; esac done } make_html() { while read -r file; do local dest=${file/.gmi/.html} dest=${dest/\/content\//\/html-output\/} printf "... %s\n" $dest cat $HTML_HEADER > $dest gmi2html < "$file" >> $dest cat $HTML_FOOTER >> $dest done < <(find $LGMI -type f -name \*.gmi) echo "Done generating HTML" echo "Copying statis assets" cp $ASSETS/* $LHTML } synchronise() { if [[ $PARAM == "html" ]]; then echo "Synchronising HTML content with remote" rsync -aP -e "ssh -p 1312" $LHTML $RHTML elif [[ $PARAM == "gmi" ]]; then echo "Synchtonising GMI content with remote" rsync -aP -e "ssh -p 1312" $LGMI $RGMI else echo "Synchtonising GMI and HTML content with remote" rsync -aP -e "ssh -p 1312" $LHTML $RHTML rsync -aP -e "ssh -p 1312" $LGMI $RGMI fi } generate() { case $1 in gmi) make_gemlogs_index ;; html) make_html ;; esac } usage() { echo "\ Usage: $0Commands: gen generates output sync synchronises files with server with rsync " } main() { case $COMMAND in gen) generate $PARAM ;; sync) synchronise ;; *) usage ;; esac } main