#!/usr/bin/env bash echo() { printf '%s\n' "$*"; } html() { : "${LIMIT:=12}" : "${FRESH_DAYS:=1}" : "${STALE_DAYS:=4}" 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 sed -e "s@https://www\.youtube\.com@https://piped.kavin.rocks@" \ -e 's@https://i\.reddit\.com@https://libreddit.spike.codes@' \ -e 's@https://twitter\.com@https://nitter.net@' } html_feed() { # html_feed FEED(file) => HTML filename="$(basename "$1")" now="$(date +%s)" fresh_secs="$((FRESH_DAYS * 24 * 60 * 60))" stale_secs="$((STALE_DAYS * 24 * 60 * 60))" ## ENTRIES entries="$(awk -v NOW="$now" \ -v FRESH_SECS="$fresh_secs" -v STALE_SECS="$stale_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 - STALE_SECS))) 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 = "@" extra_title = " title=\"enclosure\"" printf "%s", "" stamp "" } if ((link != id) && (id != enclosure) && (id ~ /^https?:/)) { stamp = "&" extra_title = " title=\"alternate link\"" printf "%s", "" stamp "" } print "" printf "" title "" print "" } END { if (show_in_sidebar) { printf "
  • ", (fresh_feed?"fresh":"stale") >> ASIDE printf "%s
  • \n", (yt ? " class=\"yt\"" : ""), FNAME, NAME >> ASIDE } printf "%s", (stamp ? stamp : ".") > "/dev/stderr" } function silo_links(link) { if (link ~ /youtube\.com/) return " youtube" if (link ~ /facebook\.com/) return " facebook" if (link ~ /twitter\.com/) return " twitter" if (link ~ /reddit\.com/) return " reddit" return "" } ' "$1" | filter_invidious)" if [ -z "$entries" ]; then return 1; fi fresh_feed='stale_feed' if echo "$entries" | grep -q 'class="[^"]*fresh"'; then fresh_feed='fresh_feed'; fi printf '
    \n' "$filename" "$fresh_feed" 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