sfeed_content 1.2 KB

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