#!/bin/sh
# some of this was taken from june's feed.sh
# (https://git.causal.agency/src/plain/www/text.causal.agency/feed.sh)
exec > "${1:-index.html}"
cat << EOF
ben's blog
EOF
ls -r -- *.txt *.gmi *.html | while read -r f; do
unset date title desc link in
case "$f" in
index.html) continue ;;
*.txt)
link="$f"
in="${f%.txt}.7"
date="$(grep '^[.]Dd' "$in" | cut -c 5-)"
title="$(grep '^[.]Nm' "$in" | cut -c 5-)"
desc=" - $(grep '^[.]Nd' "$in" | cut -c 5-)"
;;
*.gmi)
link="gemini://gemini.bvnf.space/blog/${f#[0-9][0-9][0-9]-}"
title="$(sed 1q "$f")"
date="$(sed 1d "$f")"
;;
*.html)
link="$f"
title="$(sed -n 's/.*\(.*\)<\/title>.*/\1/p' "$f")"
date="$(date -j +"%B %d, %Y" "$(sed -n 's/^.*written \([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\).*$/\1\2\30000/p' "$f")")"
;;
*) continue ;;
esac
cat <