From 7bffb9e0da2bc196061a4559449d9f6d877886bf Mon Sep 17 00:00:00 2001
From: Case Duckworth
Date: Sat, 13 Aug 2022 22:50:17 -0500
Subject: Add weeds generation
---
.gitignore | 2 ++
runsfeed | 18 ++++++++++++++++--
sfeed_weed.awk | 44 ++++++++++++++++++++++++++++++++++++++++++++
weedrc | 31 +++++++++++++++++++++++++++++++
weeds/weed.css | 35 +++++++++++++++++++++++++++++++++++
5 files changed, 128 insertions(+), 2 deletions(-)
create mode 100755 sfeed_weed.awk
create mode 100644 weedrc
create mode 100644 weeds/weed.css
diff --git a/.gitignore b/.gitignore
index ef73e7d..f300e9d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
feeds/
urls/
sfeed.old.d/
+weedsfeeds/
# generated files
*.html
*.xml
@@ -10,3 +11,4 @@ sfeed.old.d/
*.txt
*.sfeed
*.ass
+weeds/index.html
diff --git a/runsfeed b/runsfeed
index 90c128d..043723c 100755
--- a/runsfeed
+++ b/runsfeed
@@ -59,6 +59,12 @@ main() {
}'
logok "Archiving old feeds" \
'archive 60 "$sfeedpath"/*'
+ logok "Weeding" '{
+ echo
+ mkdir -p "$SFEED_OUTPUT/weeds";
+ weed > /tmp/weeds.html &&
+ mv /tmp/weeds.html "$SFEED_OUTPUT/weeds/index.html";
+ }'
if [ -f /tmp/runsfeed.ok ]; then
echo >&2 'Done.'
else
@@ -143,16 +149,24 @@ atom() ( # atom DIRECTORY [DAYS]
aggregate "$1" "$2" | sfeed_atom
)
+weed() (
+ # Generate a page for weeds.
+ runcmd sfeed_update_xargs weedrc >&2
+ . weedrc
+ aggregate "$sfeedpath" | runcmd sfeed_weed.awk
+)
+
archive() ( # sfeed_archive AGE FEED ...
age="$1"
shift
+ # shellcheck disable=2031
old="$sfeedpath/../sfeed.old.d"
mkdir -p "$old"
for feed; do
awk -v old="$(($(date +%s) - (age * 24 * 3600)))" \
-F '\t' 'int($1) > old' <"$feed" >"$feed.new"
- mv "$feed" "$old/${feed##*/}" &&
- mv "$feed.new" "$feed"
+ mv "$feed" "$old/${feed##*/}" 2>/dev/null &&
+ mv "$feed.new" "$feed" 2>/dev/null
done
)
diff --git a/sfeed_weed.awk b/sfeed_weed.awk
new file mode 100755
index 0000000..182aadf
--- /dev/null
+++ b/sfeed_weed.awk
@@ -0,0 +1,44 @@
+#!/bin/awk -f
+# convert weeds files to an html page
+BEGIN {
+ FS = "\t"
+ print ""
+ print ""
+ print "
Weed Garden"
+ print ""
+ print ""
+ print ""
+ print ""
+ print ""
+ print ""
+ print ""
+}
+
+{
+ timestamp = $1
+ title = $2
+ link = $3
+ content = $4
+ content_type = $5
+ id = $6
+ author = $7
+ enclosure = $8
+ category = $9
+ datecmd = "date -u -d \"@" timestamp "\" '+%F (%a) %R'"
+ datecmd | getline published
+ close(datecmd)
+ gsub(/\\t/, "\t", content)
+ gsub(/\\n/, "\n", content)
+ gsub(/\\/, "\\", content)
+ print ""
+ print "" title "
by " author "
"
+ print ""
+ print content
+ print ""
+}
+
+END {
+ print ""
+ print ""
+}
+
diff --git a/weedrc b/weedrc
new file mode 100644
index 0000000..ea22213
--- /dev/null
+++ b/weedrc
@@ -0,0 +1,31 @@
+# -*- sh -*-
+
+SFEED="$HOME/.sfeed"
+USER_AGENT='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'
+sfeedpath="$SFEED/weedsfeeds"
+maxjobs="$(nproc)"
+
+### Feeds #######################################################
+
+feeds() {
+ ## feed NAME FEED_URL BASE_URL ENCODING # defined by sfeedrc(5).
+ feed dozens "https://tilde.town/~dozens/rsspect/feed.xml" "https://tilde.town/~dozens/"
+ feed acdw "https://acdw.casa/weed.xml" "https://acdw.casa"
+ # feed lucidiot
+}
+
+# Fetch #########################################################
+
+fetch() { # fetch(name, url, feedfile)
+ "${NOFETCH:-false}" && return
+ curl -s -L \
+ --max-redirs 3 \
+ --header "'User-Agent: $USER_AGENT'" \
+ --fail \
+ --max-time 15 \
+ "$2"
+}
+
+# Local Variables:
+# truncate-lines: t
+# End:
diff --git a/weeds/weed.css b/weeds/weed.css
new file mode 100644
index 0000000..12b54d9
--- /dev/null
+++ b/weeds/weed.css
@@ -0,0 +1,35 @@
+body {
+ font: 16pt/1.5 serif;
+ padding: 2ch;
+ margin: auto;
+ background: #666;
+ max-width: 72ch;
+}
+
+article {
+ border: 2px ridge;
+ background: #888;
+ padding: 0 1ch;
+}
+
+article header {
+ display: flex;
+ flex-flow: row wrap;
+ align-items: baseline;
+ justify-content: space-between;
+ border-bottom: 2px groove;
+}
+
+h3 {
+ padding: 0 1ch;
+ font-style: italic;
+}
+
+time {
+ font-size: 12pt;
+}
+
+a {
+ text-decoration: none;
+ color: navy;
+}
--
cgit 1.4.1-21-gabe81