#!/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 -r 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) if ! diff -u <(sed 3d "$atom_file.tmp") <(sed 3d "$atom_file"); 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" test -n "$text" && echo "

$text

" } 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 -r token; do if [ -z "$link" ]; then link="$token" elif [ -z "$descr" ]; then descr="$token" else descr="$descr $token" fi done < <(echo "$line" | tr ' ' '\n') if grep -E -q "$IMAGE_PATTERN" <<< "$link"; then html::img "$link" "$descr" return fi # If relative link convert .gmi to .html grep -F -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 -i is_list=0 local -i is_plain=0 while IFS='' read -r line; do 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 echo "" is_plain=0 else echo "$line" | sed 's|<|\<|g; s|>|\>|g' fi continue fi case "$line" in '* '*) is_list=1 echo "