#!/usr/bin/env bash echo() { printf '%s\n' "$*"; } html() { : "${LIMIT:=25}" 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 } filter_invidious() { # Convert youtube links to invidious links host="$(cat /tmp/invidious.host)" sed "s@https://www\.youtube\.com@${host}@" } html_feed() { # html_feed FEED(file) => HTML filename="$(basename "$1")" now="$(date +%s)" fresh_days=1 fresh_secs="$((fresh_days * 24 * 60 * 60))" ## ENTRIES entries="$(awk -v NOW="$now" -v FRESH_SECS="$fresh_secs" \ -v NAME="$filename" -v FNAME="$filename" \ -v ASIDE="$aside" -v limit="$LIMIT" \ 'BEGIN { FS="\t"; fresh_feed = 0; FRESH = (NOW - FRESH_SECS); } FNR == 1 { nitem = 0; } NAME ~ /\[yt\]$/ { sub(/ \[yt\]$/, "", NAME); yt = 1; } 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 } { if (limit && (++nitem > limit)) next; timestamp=$1; title=$2; link=$3; content=unescape($4); content_type=$5; id=$6; author=$7; enclosure=$8; category=$9; if (limit && (timestamp < (NOW - (FRESH_SECS * 21)))) 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 "" printf "" title "" print "" } END { if (show_in_sidebar) { printf "", (fresh_feed?" class=\"fresh\"":"") >> ASIDE printf "%s\n", (yt ? " class=\"yt\"" : ""), FNAME, NAME >> ASIDE } printf "%s", (stamp ? stamp : ".") > "/dev/stderr" }' "$1" | filter_invidious)" if [ -z "$entries" ]; then return 1; fi echo "
" # TODO: Include a link back to the website case "$filename" in *\[yt\]) yt=" class=\"yt\"" ;; *) yt="" ;; esac fn="$(echo "$filename" | sed 's@ \[yt\]$@@')" printf '
# %s\n' "$yt" "$filename" "$fn" echo "" if [ -f "$SFEED_DATA/urls/$filename" ]; then feed_url="$(sed -n '1p;1q' "$SFEED_DATA/urls/$filename")" site_url="$(sed -n '2p;2q' "$SFEED_DATA/urls/$filename")" [ -n "$site_url" ] && printf '%s\n//\n' "$site_url" site [ -n "$feed_url" ] && printf '%s\n//\n' "$feed_url" feed fi printf '%s' top echo "
" echo "" echo "$entries" echo "
" echo "
" } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then html "$@" fi