From 6aa64d77e0f8ef2e42bdb90bc5ed3f6557e3ed81 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 17 Jul 2022 23:10:22 -0500 Subject: Initial commit --- sfeed_html.sh | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100755 sfeed_html.sh (limited to 'sfeed_html.sh') diff --git a/sfeed_html.sh b/sfeed_html.sh new file mode 100755 index 0000000..58fce30 --- /dev/null +++ b/sfeed_html.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash + +echo() { printf '%s\n' "$*"; } + +html() { + : "${LIMIT:=1}" + aside="$(mktemp /tmp/sfeed_html_aside.XXXXXX)" + cat < +
+

+mars, but with eyes +Planet ACDW

+

last updated at

+
+ +
+$(html_main "$@") + +
+ + +EOF + rm "$aside" +} + +html_head() { + cat < + + + + + + +Planet ACDW + + + + + + +EOF +} + +html_main() { + cat < +$(for file in "$@"; do html_feed "$file"; done) + +EOF +} + +html_feed() { # html_feed FEED(file) => HTML + filename="$(basename "$1")" + now="$(date +%s)" + fresh_days=7 + fresh_secs="$((fresh_days * 24 * 60 * 60))" + + ## ENTRIES + entries="$(awk -v NOW="$now" -v FRESH_SECS="$fresh_secs" \ + -v NAME="$filename" -v ASIDE="$aside" -v limit="$LIMIT" \ + 'BEGIN { FS="\t"; fresh_feed = 0; FRESH = (NOW - FRESH_SECS); } + function unescape(t) { + t = html_escape(t); + gsub(/\\\t/,"\t",t); + gsub(/\\\n/,"\n",t); + gsub(/\\\\/,"\\",t); + return t + } + function html_escape(t) { + gsub(//,"\\>",t); + gsub(/&/,"\\&",t); + return t + } + { + timestamp=$1; + title=html_escape($2); + link=$3; + content=unescape($4); + content_type=$5; + id=$6; + author=$7; + enclosure=$8; + category=$9; + + if (limit && (timestamp < (NOW - (FRESH_SECS * 3)))) next; + show_in_sidebar = 1; + #print timestamp, title, link > "/dev/stderr"; + + date_cmd = "date -d \"@" timestamp "\" +\"%F %R\"" + if (timestamp) { + date_cmd | getline ts; + close(date_cmd); + } + + fresh = (timestamp >= FRESH) + if (fresh) fresh_feed = 1; + + print "" + print "" ts "" + printf "%s", "" + if (enclosure) { + stamp = "@" + printf "%s", "" stamp "" + } + if ((link != id) && (id != enclosure) && (id ~ /^https?:/)) { + stamp = "#" + printf "%s", "" stamp "" + } + print "" + print "" title "" + print "" + } + END { + if (show_in_sidebar) { + printf "", (fresh_feed?" class=\"fresh\"":"") >> ASIDE + printf "%s\n", NAME, NAME >> ASIDE + } + printf "%s", (stamp ? stamp : ".") > "/dev/stderr" + }' "$1")" + if [ -z "$entries" ]; then return 1; fi + echo "
" + # TODO: Include a link back to the website + printf '

# %s

\n' "$filename" "$filename" + printf '%s
' "[back to top]" + echo "" + echo "$entries" + echo "
" + echo "
" +} + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + html "$@" +fi -- cgit 1.4.1-21-gabe81