From 4cfa033083b516205860fe3b608a10b2b4fdc2b7 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 30 Apr 2021 07:23:58 +0100 Subject: refactor --- buetow.org.conf | 5 + buetow.org.sh | 300 +++++++++++++++++++++++++++++++++++++++++++++++++++ content/footer.html | 2 - content/header.html | 19 ---- doit.sh | 305 ---------------------------------------------------- footer.html | 2 + header.html | 19 ++++ 7 files changed, 326 insertions(+), 326 deletions(-) create mode 100644 buetow.org.conf create mode 100755 buetow.org.sh delete mode 100644 content/footer.html delete mode 100644 content/header.html delete mode 100755 doit.sh create mode 100644 footer.html create mode 100644 header.html diff --git a/buetow.org.conf b/buetow.org.conf new file mode 100644 index 00000000..ba65a8cc --- /dev/null +++ b/buetow.org.conf @@ -0,0 +1,5 @@ +declare -r DOMAIN=buetow.org +declare -r CONTENT_DIR=./content +declare -r AUTHOR="Paul Buetow" +declare -r EMAIL="comments@mx.buetow.org" +declare -r IMAGE_PATTERN='\.(jpg|png|gif)$' diff --git a/buetow.org.sh b/buetow.org.sh new file mode 100755 index 00000000..c44e0646 --- /dev/null +++ b/buetow.org.sh @@ -0,0 +1,300 @@ +#!/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.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 "$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 "" - 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 "