sfeed_content (1276B) - raw


      1 #!/bin/sh
      2 # Content viewer for sfeed(5) lines.
      3 
      4 # The locale is set to "C" for performance. The input is always UTF-8.
      5 LC_ALL=C awk -F '\t' '
      6 function unescape(s) {
      7 	# use the character "\x01" as a temporary replacement for "\".
      8 	gsub("\\\\\\\\", "\x01", s);
      9 	gsub("\\\\n", "\n", s);
     10 	gsub("\\\\t", "\t", s);
     11 	gsub("\x01", "\\", s); # restore "\x01" to "\".
     12 	return s;
     13 }
     14 BEGIN {
     15 	htmlconv = ENVIRON["SFEED_HTMLCONV"];
     16 	if (!length(htmlconv))
     17 		htmlconv = "lynx -stdin -dump " \
     18 			"-underline_links -image_links " \
     19 			"-display_charset=\"utf-8\" -assume_charset=\"utf-8\" ";
     20 }
     21 {
     22 	if (previtem)
     23 		print "\f";
     24 	previtem = 1;
     25 
     26 	print "Title:     " $2;
     27 	if (length($7))
     28 		print "Author:    " $7;
     29 	if (length($9)) {
     30 		categories = $9;
     31 		gsub("\\|", ", ", categories);
     32 		print "Category:  " categories;
     33 	}
     34 	if (length($3))
     35 		print "Link:      " $3;
     36 	if (length($8))
     37 		print "Enclosure: " $8;
     38 	if (!length($4))
     39 		next;
     40 	print "";
     41 	if ($5 == "html") {
     42 		# use the link of the item as the base URL for relative URLs in
     43 		# HTML content.
     44 		base = $3;
     45 		if (length(base)) {
     46 			gsub("\"", "%22", base); # encode quotes.
     47 			base = "<base href=\"" base "\"/>\n";
     48 		}
     49 		print base unescape($4) | htmlconv;
     50 		close(htmlconv);
     51 	} else {
     52 		print unescape($4);
     53 	}
     54 }' "$@" | \
     55 ${PAGER:-less -R}