#!/usr/bin/env bash declare -r ARG=$1; shift source buetow.org.conf ## Test module assert::equals () { local -r result="$1"; shift local -r expected="$1"; shift if [ "$result" != "$expected" ]; then cat < $atom_file.tmp $now $DOMAIN feed $SUBTITLE gemini://$DOMAIN/ ATOMHEADER while read gmi_file; do # Load cached meta information about the post. source <(atom::meta $now $gemfeed_dir/$gmi_file) cat <> $atom_file.tmp $meta_title gemini://$DOMAIN/gemfeed/$gmi_file $meta_date $meta_summary $meta_author $meta_email ATOMENTRY done < <(ls $gemfeed_dir | sort -r | grep '.gmi$' | head -n $ATOM_MAX_ENTRIES) cat <> $atom_file.tmp ATOMFOOTER # Delete the 3rd line of the atom feeds (global feed update timestamp) diff -u <(sed 3d $atom_file.tmp) <(sed 3d $atom_file) if [ $? -ne 0 ]; then echo "Feed got something new!" mv $atom_file.tmp $atom_file git add $atom_file else echo "Nothing really new in the feed" rm $atom_file.tmp fi } ## HTML module html::paragraph () { local -r text="$1" if [ ! -z "$text" ]; then echo "

$text

" fi } html::heading () { local -r text=$(sed -E 's/^#+ //' <<< "$1") local -r level="$2" echo "$text" } html::quote () { local -r quote="${1/> }" echo "
$quote
" } html::img () { local link="$1"; shift local descr="$1"; shift if [ -z "$descr" ]; then echo -n "" else echo -n "$descr:" echo -n "\"$descr\"" fi echo "
" } html::link () { local -r line="${1/=> }" local link local descr while read token; do if [ -z "$link" ]; then link="$token" elif [ -z "$descr" ]; then descr="$token" else descr="$descr $token" fi done < <(echo "$line" | tr ' ' '\n') egrep -q "$IMAGE_PATTERN" <<< $link if [ $? -eq 0 ]; then html::img "$link" "$descr" return fi # If relative link convert .gmi to .html fgrep -q '://' <<< $link || link=${link/.gmi/.html} # If no description use link itself test -z "$descr" && descr="$link" echo "$descr
" } html::gemini2html () { local -r gmi_file=$1 local -r html_file=$(sed 's/.gmi/.html/; s/gemtext/html/;' <<< $gmi_file) local -i is_list=0 local -i line_nr local -i is_plain=0 local -i plain_start while IFS='' read line; do let line_nr++ if [ $is_list -eq 1 ]; then if [[ "$line" == '* '* ]]; then echo "
  • ${line/\* /}
  • " else is_list=0 echo "" fi continue elif [ $is_plain -eq 1 ]; then if [[ "$line" == '```'* ]]; then local -i plain_end=$(( line_nr - 1 )) # Use sed, as escaping \ in bash strings is hell! sed -n ${plain_start},${plain_end}p $gmi_file echo "" is_plain=0 fi continue fi case "$line" in '* '*) is_list=1 echo "