From 2222a1aa7306200528de3d00edc7330fb4400c4f Mon Sep 17 00:00:00 2001
From: Case Duckworth
Date: Sat, 23 Jul 2022 22:50:20 -0500
Subject: Convert sfeed_html.sh to sfeed_html.awk
---
sfeed_html.awk | 341 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sfeed_html.sh | 223 -------------------------------------
2 files changed, 341 insertions(+), 223 deletions(-)
create mode 100755 sfeed_html.awk
delete mode 100755 sfeed_html.sh
diff --git a/sfeed_html.awk b/sfeed_html.awk
new file mode 100755
index 0000000..8477677
--- /dev/null
+++ b/sfeed_html.awk
@@ -0,0 +1,341 @@
+#!/bin/awk -f
+# Convert sfeed(1) formatted files into an HTML webpage.
+# Usage: sfeed_html.awk -- FILES...
+
+## Set up variables
+BEGIN {
+ # Sidebar
+ if (! ASIDE) {
+ ASIDE = envor("SFEED_HTML_ASIDE", "/tmp/sfeed-aside.html")
+ }
+ print > ASIDE # clear out ASIDE
+ in_aside = 0 # Don't show the feed in the sidebar
+ # Formatting
+ if (! DATEFMT) {
+ DATEFMT = envor("SFEED_HTML_DATEFMT", "%F %RZ")
+ }
+ if (! TITLE) {
+ TITLE = envor("SFEED_HTML_TITLE", "Planet ACDW")
+ }
+ if (! SEPARATOR) {
+ SEPARATOR = envor("SFEED_HTML_SEPARATOR", "//")
+ }
+ if (! ALT_LINK_STAMP) {
+ ALT_LINK_STAMP = envor("SFEED_ALT_LINK_STAMP", "&")
+ }
+ if (! ENCLOSURE_STAMP) {
+ ENCLOSURE_STAMP = envor("SFEED_ENCLOSURE_STAMP", "@")
+ }
+ if (! SILO_STAMP) {
+ SILO_STAMP = envor("SFEED_SILO_STAMP", "%")
+ }
+ # Limiting posts...
+ ## by time
+ if (! NOW) {
+ datecmd = "date +%s"
+ datecmd | getline NOW
+ close(datecmd)
+ }
+ if (! FRESHDAYS) {
+ FRESHDAYS = envor("SFEED_FRESHDAYS", 1.5)
+ }
+ if (! STALEDAYS) {
+ STALEDAYS = envor("SFEED_STALEDAYS", 4)
+ }
+ fresh_secs = FRESHDAYS * 24 * 60 * 60
+ stale_secs = STALEDAYS * 24 * 60 * 60
+ fresh_age = (NOW - fresh_secs)
+ stale_age = (NOW - stale_secs)
+ ## by number
+ if (! LIMIT) {
+ # If LIMIT == -1, ignore time limit as well.
+ LIMIT = envor("SFEED_LIMIT", 20)
+ }
+ # Alternate URLs for siloed content
+ if (! YOUTUBE_ALT_URL) {
+ YOUTUBE_ALT_URL = envor("SFEED_YOUTUBE_ALT_URL", "https://piped.kavin.rocks")
+ }
+ if (! TWITTER_ALT_URL) {
+ TWITTER_ALT_URL = envor("SFEED_TWITTER_ALT_URL", "https://nitter.net")
+ }
+ if (! REDDIT_ALT_URL) {
+ REDDIT_ALT_URL = envor("SFEED_REDDIT_ALT_URL", "https://libreddit.spike.codes")
+ }
+ # Awk and convenience constants
+ FS = "\t"
+ STDERR = "/dev/stderr"
+}
+
+## Print HTML header
+BEGIN {
+ fortunecmd = "fortune"
+ fortunecmd | getline LOGO_TITLE
+ close(fortunecmd)
+ sub(/"/, "", LOGO_TITLE)
+ datecmd = "date -u +'" DATEFMT "'"
+ datecmd | getline UPDATE_TIME
+ close(datecmd)
+ print ""
+ print ""
+ #
+ print ""
+ print ""
+ print ""
+ print ""
+ print ""
+ print "" TITLE ""
+ print ""
+ print ""
+ print ""
+ print ""
+ print ""
+ print ""
+ print ""
+ print ""
+ #
+ print ""
+ #