diff options
author | Case Duckworth | 2022-08-13 22:50:17 -0500 |
---|---|---|
committer | Case Duckworth | 2022-08-13 22:50:17 -0500 |
commit | 7bffb9e0da2bc196061a4559449d9f6d877886bf (patch) | |
tree | 68ce2af86ebf57c6fc8bdc94e8b3dc466f032bf8 | |
parent | Add noa's sotw (diff) | |
download | sfeed-7bffb9e0da2bc196061a4559449d9f6d877886bf.tar.gz sfeed-7bffb9e0da2bc196061a4559449d9f6d877886bf.zip |
Add weeds generation
-rw-r--r-- | .gitignore | 2 | ||||
-rwxr-xr-x | runsfeed | 18 | ||||
-rwxr-xr-x | sfeed_weed.awk | 44 | ||||
-rw-r--r-- | weedrc | 31 | ||||
-rw-r--r-- | weeds/weed.css | 35 |
5 files changed, 128 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore index ef73e7d..f300e9d 100644 --- a/.gitignore +++ b/.gitignore | |||
@@ -2,6 +2,7 @@ | |||
2 | feeds/ | 2 | feeds/ |
3 | urls/ | 3 | urls/ |
4 | sfeed.old.d/ | 4 | sfeed.old.d/ |
5 | weedsfeeds/ | ||
5 | # generated files | 6 | # generated files |
6 | *.html | 7 | *.html |
7 | *.xml | 8 | *.xml |
@@ -10,3 +11,4 @@ sfeed.old.d/ | |||
10 | *.txt | 11 | *.txt |
11 | *.sfeed | 12 | *.sfeed |
12 | *.ass | 13 | *.ass |
14 | weeds/index.html | ||
diff --git a/runsfeed b/runsfeed index 90c128d..043723c 100755 --- a/runsfeed +++ b/runsfeed | |||
@@ -59,6 +59,12 @@ main() { | |||
59 | }' | 59 | }' |
60 | logok "Archiving old feeds" \ | 60 | logok "Archiving old feeds" \ |
61 | 'archive 60 "$sfeedpath"/*' | 61 | 'archive 60 "$sfeedpath"/*' |
62 | logok "Weeding" '{ | ||
63 | echo | ||
64 | mkdir -p "$SFEED_OUTPUT/weeds"; | ||
65 | weed > /tmp/weeds.html && | ||
66 | mv /tmp/weeds.html "$SFEED_OUTPUT/weeds/index.html"; | ||
67 | }' | ||
62 | if [ -f /tmp/runsfeed.ok ]; then | 68 | if [ -f /tmp/runsfeed.ok ]; then |
63 | echo >&2 'Done.' | 69 | echo >&2 'Done.' |
64 | else | 70 | else |
@@ -143,16 +149,24 @@ atom() ( # atom DIRECTORY [DAYS] | |||
143 | aggregate "$1" "$2" | sfeed_atom | 149 | aggregate "$1" "$2" | sfeed_atom |
144 | ) | 150 | ) |
145 | 151 | ||
152 | weed() ( | ||
153 | # Generate a page for weeds. | ||
154 | runcmd sfeed_update_xargs weedrc >&2 | ||
155 | . weedrc | ||
156 | aggregate "$sfeedpath" | runcmd sfeed_weed.awk | ||
157 | ) | ||
158 | |||
146 | archive() ( # sfeed_archive AGE FEED ... | 159 | archive() ( # sfeed_archive AGE FEED ... |
147 | age="$1" | 160 | age="$1" |
148 | shift | 161 | shift |
162 | # shellcheck disable=2031 | ||
149 | old="$sfeedpath/../sfeed.old.d" | 163 | old="$sfeedpath/../sfeed.old.d" |
150 | mkdir -p "$old" | 164 | mkdir -p "$old" |
151 | for feed; do | 165 | for feed; do |
152 | awk -v old="$(($(date +%s) - (age * 24 * 3600)))" \ | 166 | awk -v old="$(($(date +%s) - (age * 24 * 3600)))" \ |
153 | -F '\t' 'int($1) > old' <"$feed" >"$feed.new" | 167 | -F '\t' 'int($1) > old' <"$feed" >"$feed.new" |
154 | mv "$feed" "$old/${feed##*/}" && | 168 | mv "$feed" "$old/${feed##*/}" 2>/dev/null && |
155 | mv "$feed.new" "$feed" | 169 | mv "$feed.new" "$feed" 2>/dev/null |
156 | done | 170 | done |
157 | ) | 171 | ) |
158 | 172 | ||
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 @@ | |||
1 | #!/bin/awk -f | ||
2 | # convert weeds files to an html page | ||
3 | BEGIN { | ||
4 | FS = "\t" | ||
5 | print "<!DOCTYPE html>" | ||
6 | print "<html>" | ||
7 | print "<head><title>Weed Garden</title>" | ||
8 | print "<meta charset=\"utf-8\">" | ||
9 | print "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">" | ||
10 | print "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" | ||
11 | print "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" | ||
12 | print "<link rel=\"stylesheet\" type=\"text/css\" href=\"weed.css\">" | ||
13 | print "</head>" | ||
14 | print "<body>" | ||
15 | } | ||
16 | |||
17 | { | ||
18 | timestamp = $1 | ||
19 | title = $2 | ||
20 | link = $3 | ||
21 | content = $4 | ||
22 | content_type = $5 | ||
23 | id = $6 | ||
24 | author = $7 | ||
25 | enclosure = $8 | ||
26 | category = $9 | ||
27 | datecmd = "date -u -d \"@" timestamp "\" '+%F (%a) %R'" | ||
28 | datecmd | getline published | ||
29 | close(datecmd) | ||
30 | gsub(/\\t/, "\t", content) | ||
31 | gsub(/\\n/, "\n", content) | ||
32 | gsub(/\\/, "\\", content) | ||
33 | print "<article>" | ||
34 | print "<header><h2>" title "</h2><h3>by " author "</h3>" | ||
35 | print "<time>" published "</time></header>" | ||
36 | print content | ||
37 | print "</article>" | ||
38 | } | ||
39 | |||
40 | END { | ||
41 | print "</body>" | ||
42 | print "</html>" | ||
43 | } | ||
44 | |||
diff --git a/weedrc b/weedrc new file mode 100644 index 0000000..ea22213 --- /dev/null +++ b/weedrc | |||
@@ -0,0 +1,31 @@ | |||
1 | # -*- sh -*- | ||
2 | |||
3 | SFEED="$HOME/.sfeed" | ||
4 | USER_AGENT='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0' | ||
5 | sfeedpath="$SFEED/weedsfeeds" | ||
6 | maxjobs="$(nproc)" | ||
7 | |||
8 | ### Feeds ####################################################### | ||
9 | |||
10 | feeds() { | ||
11 | ## feed NAME FEED_URL BASE_URL ENCODING # defined by sfeedrc(5). | ||
12 | feed dozens "https://tilde.town/~dozens/rsspect/feed.xml" "https://tilde.town/~dozens/" | ||
13 | feed acdw "https://acdw.casa/weed.xml" "https://acdw.casa" | ||
14 | # feed lucidiot | ||
15 | } | ||
16 | |||
17 | # Fetch ######################################################### | ||
18 | |||
19 | fetch() { # fetch(name, url, feedfile) | ||
20 | "${NOFETCH:-false}" && return | ||
21 | curl -s -L \ | ||
22 | --max-redirs 3 \ | ||
23 | --header "'User-Agent: $USER_AGENT'" \ | ||
24 | --fail \ | ||
25 | --max-time 15 \ | ||
26 | "$2" | ||
27 | } | ||
28 | |||
29 | # Local Variables: | ||
30 | # truncate-lines: t | ||
31 | # 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 @@ | |||
1 | body { | ||
2 | font: 16pt/1.5 serif; | ||
3 | padding: 2ch; | ||
4 | margin: auto; | ||
5 | background: #666; | ||
6 | max-width: 72ch; | ||
7 | } | ||
8 | |||
9 | article { | ||
10 | border: 2px ridge; | ||
11 | background: #888; | ||
12 | padding: 0 1ch; | ||
13 | } | ||
14 | |||
15 | article header { | ||
16 | display: flex; | ||
17 | flex-flow: row wrap; | ||
18 | align-items: baseline; | ||
19 | justify-content: space-between; | ||
20 | border-bottom: 2px groove; | ||
21 | } | ||
22 | |||
23 | h3 { | ||
24 | padding: 0 1ch; | ||
25 | font-style: italic; | ||
26 | } | ||
27 | |||
28 | time { | ||
29 | font-size: 12pt; | ||
30 | } | ||
31 | |||
32 | a { | ||
33 | text-decoration: none; | ||
34 | color: navy; | ||
35 | } | ||