summaryrefslogtreecommitdiff
path: root/sfeed_content
blob: 2d0ee2337f36a13516e643be767ecdbafa85bcfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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}