diff options
Diffstat (limited to 'sfeed_html.sh')
-rwxr-xr-x | sfeed_html.sh | 223 |
1 files changed, 0 insertions, 223 deletions
diff --git a/sfeed_html.sh b/sfeed_html.sh deleted file mode 100755 index 3965a87..0000000 --- a/sfeed_html.sh +++ /dev/null | |||
@@ -1,223 +0,0 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | echo() { printf '%s\n' "$*"; } | ||
4 | |||
5 | html() { | ||
6 | : "${LIMIT:=12}" | ||
7 | : "${FRESH_DAYS:=1}" | ||
8 | : "${STALE_DAYS:=4}" | ||
9 | aside="$(mktemp /tmp/sfeed_html_aside.XXXXXX)" | ||
10 | cat <<EOF | ||
11 | $(html_head) | ||
12 | <body> | ||
13 | <header> | ||
14 | <h1> | ||
15 | <a href="index.html"><img src="mars-eyes.png" | ||
16 | title="$(fortune | tr -d '"')" | ||
17 | width="40" height="39" | ||
18 | alt="mars, but with eyes" /></a> | ||
19 | Planet ACDW</h1> | ||
20 | <p class="last-updated">last updated at <time>$(date -R)</time></p> | ||
21 | </header> | ||
22 | <nav> | ||
23 | <a href="#" id="stalebutton">hide stale</a> | ||
24 | // | ||
25 | <a href="feeds-short.xml">rss</a> | ||
26 | // | ||
27 | <a href="feeds.html">all</a> | ||
28 | (<a href="feeds.xml">rss</a>) | ||
29 | // | ||
30 | <a href="feeds.txt">twtxt</a> | ||
31 | // | ||
32 | <a href="feeds.opml">opml</a> | ||
33 | </nav> | ||
34 | <main> | ||
35 | $(html_main "$@") | ||
36 | <aside><ul id="feedlist">$(cat "$aside")</ul></aside> | ||
37 | </main> | ||
38 | <footer> | ||
39 | Generated by <a href="https://codemadness.org/sfeed-simple-feed-parser.html">sfeed</a> | ||
40 | using <a href="https://git.acdw.net/sfeed/">this configuration</a>. | ||
41 | <a href="mailto:planet@me.acdw.net">suggest a feed!</a> | ||
42 | </footer> | ||
43 | <script> | ||
44 | var staleHidden = false; | ||
45 | var staleItems = new Set(document.getElementsByClassName("stale")); | ||
46 | var staleFeeds = new Set(document.getElementsByClassName("stale_feed")); | ||
47 | var feedlistFeeds = new Set(document.getElementById("feedlist").children); | ||
48 | function hideShowStale(){ | ||
49 | var display; | ||
50 | if (staleHidden) { | ||
51 | display = null; staleHidden = false; | ||
52 | flBG = null; flBB = null; | ||
53 | } else { | ||
54 | display = 'none'; staleHidden = true; | ||
55 | flBG = 'inherit'; flBB = '1px solid'; | ||
56 | } | ||
57 | staleItems.forEach(e => { e.style.display = display; }); | ||
58 | staleFeeds.forEach(e => { e.style.display = display; }); | ||
59 | if (window.innerWidth > 720) { | ||
60 | feedlistFeeds.forEach(e => { e.style.background = flBG; e.style.borderBottom = flBB; }); | ||
61 | } | ||
62 | } | ||
63 | var button = document.getElementById("stalebutton"); | ||
64 | button.addEventListener("click", function() { | ||
65 | hideShowStale(); | ||
66 | if (staleHidden) { button.textContent = "show stale"; } | ||
67 | else { button.textContent = "hide stale"; } | ||
68 | }); | ||
69 | </script> | ||
70 | </body> | ||
71 | </html> | ||
72 | EOF | ||
73 | rm "$aside" | ||
74 | } | ||
75 | |||
76 | html_head() { | ||
77 | cat <<EOF | ||
78 | <!DOCTYPE html> | ||
79 | <html> | ||
80 | <head> | ||
81 | <meta charset="utf-8"> | ||
82 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
83 | <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> | ||
84 | <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
85 | <title>Planet ACDW</title> | ||
86 | <link rel="stylesheet" type="text/css" href="style.css"> | ||
87 | <link rel="shortcut icon" type="image/png" href="mars-eyes.png"> | ||
88 | <link rel="alternate" type="application/atom+xml" title="rss (full)" href="feeds.xml"> | ||
89 | <link rel="alternate" type="application/atom+xml" title="rss (short)" href="feeds-short.xml"> | ||
90 | <link rel="alternate" type="application/xml" title="opml" href="feeds.opml"> | ||
91 | <link rel="alternate" type="text/plain" title="twtxt" href="feeds.txt"> | ||
92 | </head> | ||
93 | EOF | ||
94 | } | ||
95 | |||
96 | html_main() { | ||
97 | cat <<EOF | ||
98 | <section id="list"> | ||
99 | $(for file in "$@"; do html_feed "$file"; done) | ||
100 | </section> | ||
101 | EOF | ||
102 | } | ||
103 | |||
104 | filter_invidious() { | ||
105 | # Convert youtube links to invidious links | ||
106 | sed -e "s@https://www\.youtube\.com@https://piped.kavin.rocks@" \ | ||
107 | -e 's@https://i\.reddit\.com@https://libreddit.spike.codes@' \ | ||
108 | -e 's@https://twitter\.com@https://nitter.net@' | ||
109 | } | ||
110 | |||
111 | html_feed() { # html_feed FEED(file) => HTML | ||
112 | filename="$(basename "$1")" | ||
113 | now="$(date +%s)" | ||
114 | fresh_secs="$((FRESH_DAYS * 24 * 60 * 60))" | ||
115 | stale_secs="$((STALE_DAYS * 24 * 60 * 60))" | ||
116 | |||
117 | ## ENTRIES | ||
118 | entries="$(awk -v NOW="$now" \ | ||
119 | -v FRESH_SECS="$fresh_secs" -v STALE_SECS="$stale_secs" \ | ||
120 | -v NAME="$filename" -v FNAME="$filename" \ | ||
121 | -v ASIDE="$aside" -v limit="$LIMIT" \ | ||
122 | 'BEGIN { FS="\t"; fresh_feed = 0; FRESH = (NOW - FRESH_SECS); } | ||
123 | FNR == 1 { nitem = 0; } | ||
124 | NAME ~ /\[yt\]$/ { sub(/ \[yt\]$/, "", NAME); yt = 1; } | ||
125 | function unescape(t) { | ||
126 | t = html_escape(t); | ||
127 | gsub(/\\\t/,"\t",t); | ||
128 | gsub(/\\\n/,"\n",t); | ||
129 | gsub(/\\\\/,"\\",t); | ||
130 | return t | ||
131 | } | ||
132 | function html_escape(t) { | ||
133 | gsub(/</,"\\<",t); | ||
134 | gsub(/>/,"\\>",t); | ||
135 | gsub(/&/,"\\&",t); | ||
136 | return t | ||
137 | } | ||
138 | { | ||
139 | if (limit && (++nitem > limit)) next; | ||
140 | timestamp=$1; | ||
141 | title=$2; | ||
142 | link=$3; | ||
143 | content=unescape($4); | ||
144 | content_type=$5; | ||
145 | id=$6; | ||
146 | author=$7; | ||
147 | enclosure=$8; | ||
148 | category=$9; | ||
149 | |||
150 | if (limit && (timestamp < (NOW - STALE_SECS))) next; | ||
151 | show_in_sidebar = 1; | ||
152 | #print timestamp, title, link > "/dev/stderr"; | ||
153 | |||
154 | date_cmd = "date -d \"@" timestamp "\" +\"%F %R\"" | ||
155 | if (timestamp) { | ||
156 | date_cmd | getline ts; | ||
157 | close(date_cmd); | ||
158 | } | ||
159 | |||
160 | fresh = (timestamp >= FRESH) | ||
161 | if (fresh) fresh_feed = 1; | ||
162 | |||
163 | print "<tr class=\"entry " (fresh ? "fresh" : "stale") "\">" | ||
164 | print "<td class=\"entry-timestamp\">" ts "</td>" | ||
165 | printf "%s", "<td class=\"entry-extra\">" | ||
166 | if (enclosure) { | ||
167 | stamp = "@" | ||
168 | extra_title = " title=\"enclosure\"" | ||
169 | printf "%s", "<a href=\"" enclosure "\"" extra_title " target=\"_blank\">" stamp "</a>" | ||
170 | } | ||
171 | if ((link != id) && (id != enclosure) && (id ~ /^https?:/)) { | ||
172 | stamp = "&" | ||
173 | extra_title = " title=\"alternate link\"" | ||
174 | printf "%s", "<a href=\"" id "\"" extra_title " target=\"_blank\">" stamp "</a>" | ||
175 | } | ||
176 | print "</td>" | ||
177 | printf "<td class=\"entry-title%s", silo_links(link) | ||
178 | print "\"><a href=\"" link "\" target=\"_blank\">" title "</a></td>" | ||
179 | print "</tr>" | ||
180 | } | ||
181 | END { | ||
182 | if (show_in_sidebar) { | ||
183 | printf "<li class=\"%s\">", (fresh_feed?"fresh":"stale") >> ASIDE | ||
184 | printf "<a%s href=\"#%s\">%s</a></li>\n", (yt ? " class=\"yt\"" : ""), FNAME, NAME >> ASIDE | ||
185 | } | ||
186 | printf "%s", (stamp ? stamp : ".") > "/dev/stderr" | ||
187 | } | ||
188 | function silo_links(link) { | ||
189 | if (link ~ /youtube\.com/) return " youtube" | ||
190 | if (link ~ /facebook\.com/) return " facebook" | ||
191 | if (link ~ /twitter\.com/) return " twitter" | ||
192 | if (link ~ /reddit\.com/) return " reddit" | ||
193 | return "" | ||
194 | } | ||
195 | ' "$1" | filter_invidious)" | ||
196 | if [ -z "$entries" ]; then return 1; fi | ||
197 | fresh_feed='stale_feed' | ||
198 | if echo "$entries" | grep -q 'class="[^"]*fresh"'; then fresh_feed='fresh_feed'; fi | ||
199 | printf '<section id="%s" class="%s">\n' "$filename" "$fresh_feed" | ||
200 | case "$filename" in | ||
201 | *\[yt\]) yt=" class=\"yt\"" ;; | ||
202 | *) yt="" ;; | ||
203 | esac | ||
204 | fn="$(echo "$filename" | sed 's@ \[yt\]$@@')" | ||
205 | printf '<header><h2%s><a href="#%s">#</a> %s</h2>\n' "$yt" "$filename" "$fn" | ||
206 | echo "<span class=\"flinks\">" | ||
207 | if [ -f "$SFEED_DATA/urls/$filename" ]; then | ||
208 | feed_url="$(sed -n '1p;1q' "$SFEED_DATA/urls/$filename")" | ||
209 | site_url="$(sed -n '2p;2q' "$SFEED_DATA/urls/$filename")" | ||
210 | [ -n "$site_url" ] && printf '<a class="site-url" href="%s">%s</a>\n//\n' "$site_url" site | ||
211 | [ -n "$feed_url" ] && printf '<a class="feed-url" href="%s">%s</a>\n//\n' "$feed_url" feed | ||
212 | fi | ||
213 | printf '<a class="top" href="#">%s</a>' top | ||
214 | echo "</span></header>" | ||
215 | echo "<table class=\"entries\">" | ||
216 | echo "$entries" | ||
217 | echo "</table>" | ||
218 | echo "</section>" | ||
219 | } | ||
220 | |||
221 | if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | ||
222 | html "$@" | ||
223 | fi | ||