sfeed_opml_export 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. # load config (evaluate shellscript).
  3. # loadconfig(configfile)
  4. loadconfig() {
  5. # allow to specify config via argv[1].
  6. if [ "$1" != "" ]; then
  7. # get absolute path of config file required for including.
  8. config="$1"
  9. path=$(readlink -f "${config}" 2>/dev/null)
  10. else
  11. # default config location.
  12. config="$HOME/.sfeed/sfeedrc"
  13. path="${config}"
  14. fi
  15. # config is loaded here to be able to override $sfeedpath or functions.
  16. if [ -r "${path}" ]; then
  17. . "${path}"
  18. else
  19. printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2
  20. echo "See the sfeedrc.example file or the sfeedrc(5) man page for an example." >&2
  21. exit 1
  22. fi
  23. }
  24. # override feed function to output OPML XML.
  25. # feed(name, feedurl, [basesiteurl], [encoding])
  26. feed() {
  27. # uses the characters 0x1f and 0x1e as a separator.
  28. printf '%s\037%s\036' "$1" "$2"
  29. }
  30. # load config file.
  31. loadconfig "$1"
  32. cat <<!
  33. <?xml version="1.0" encoding="UTF-8"?>
  34. <opml version="1.0">
  35. <head>
  36. <title>OPML export from sfeed</title>
  37. </head>
  38. <body>
  39. !
  40. feeds | LC_ALL=C awk '
  41. BEGIN {
  42. FS = "\x1f"; RS = "\x1e";
  43. }
  44. {
  45. gsub("&", "\\&amp;");
  46. gsub("\"", "\\&quot;");
  47. gsub("'"'"'", "\\&#39;");
  48. gsub("<", "\\&lt;");
  49. gsub(">", "\\&gt;");
  50. print "\t<outline type=\"rss\" title=\"" $1 "\" text=\"" $1 "\" xmlUrl=\"" $2 "\"/>";
  51. }'
  52. cat <<!
  53. </body>
  54. </opml>
  55. !