#!/usr/bin/env bash declare -r ARG=$1; shift ## Config section declare -r DOMAIN=buetow.org declare -r CONTENT_DIR=./content declare -r AUTHOR="Paul Buetow" declare -r EMAIL="comments@mx.buetow.org" ## Test module assert::equals () { local -r result="$1"; shift local -r expected="$1"; shift if [ "$result" != "$expected" ]; then cat < $atom.tmp $DOMAIN feed Putting the dot before the org! gemini://$DOMAIN $updated ATOMHEADER ls $gemfeed_dir | sort -r | grep '.gmi$' | while read post; do local title=$(sed -n '/^# / { s/# //; p; q; }' $gemfeed_dir/$post) local first_paragraph=$(sed -n '/^[A-Z]/ { p; q; }' $gemfeed_dir/$post) cat <> $atom.tmp $title gemini://$DOMAIN/gemfeed/$post $updated $first_paragraph $AUTHOR $EMAIL ATOMENTRY done cat <> $atom.tmp ATOMFOOTER mv $atom.tmp $atom git add $atom } ## 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 '\.(jpg|png|gif)$' <<< $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 "