summaryrefslogtreecommitdiff
path: root/sfeed_content
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2021-11-26 12:10:05 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2021-11-26 12:10:05 +0100
commit3cb7df56e0204bb8b0799a8317ef5a5f38802c7b (patch)
treee09077073cdcfc14d4202f6904935f2fa9de57bc /sfeed_content
parent618a6561cd09f489e30ab652da1649a0d1fec1d5 (diff)
import sfeed_curses
Import sfeed_curses into sfeed. The files are based of the commit 8e151ce48b503ad0ff0e24cb1be3bc93d6fbd895
Diffstat (limited to 'sfeed_content')
-rwxr-xr-xsfeed_content53
1 files changed, 53 insertions, 0 deletions
diff --git a/sfeed_content b/sfeed_content
new file mode 100755
index 0000000..2d0ee23
--- /dev/null
+++ b/sfeed_content
@@ -0,0 +1,53 @@
+#!/bin/sh
+# Content viewer for sfeed(5) lines.
+
+# The locale is set to "C" for performance. The input is always UTF-8.
+LC_ALL=C awk -F '\t' '
+function unescape(s) {
+ # use the character "\x01" as a temporary replacement for "\".
+ gsub("\\\\\\\\", "\x01", s);
+ gsub("\\\\n", "\n", s);
+ gsub("\\\\t", "\t", s);
+ gsub("\x01", "\\", s); # restore "\x01" to "\".
+ return s;
+}
+BEGIN {
+ htmlconv = "lynx -stdin -dump " \
+ "-underline_links -image_links " \
+ "-display_charset=\"utf-8\" -assume_charset=\"utf-8\" ";
+}
+{
+ if (previtem)
+ print "\f";
+ previtem = 1;
+
+ print "Title: " $2;
+ if (length($7))
+ print "Author: " $7;
+ if (length($9)) {
+ categories = $9;
+ gsub("\\|", ", ", categories);
+ print "Category: " categories;
+ }
+ if (length($3))
+ print "Link: " $3;
+ if (length($8))
+ print "Enclosure: " $8;
+ if (!length($4))
+ next;
+ print "";
+ if ($5 == "html") {
+ # use the link of the item as the base URL for relative URLs in
+ # HTML content.
+ base = $3;
+ if (length(base)) {
+ gsub("\"", "%22", base); # encode quotes.
+ base = "<base href=\"" base "\"/>\n";
+ }
+ print base unescape($4) | htmlconv;
+ close(htmlconv);
+ } else {
+ print unescape($4);
+ }
+}' "$@" | \
+${PAGER:-less -R}