web and wiki

atom.sh 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. # a terribly inefficient atom.xml generator
  3. # See LICENSE file for copyright and license details.
  4. #
  5. # https://en.wikipedia.org/wiki/Atom_(standard)#Example_of_an_Atom_1.0_feed
  6. printf " * generating atom feed\n"
  7. cat <<EOF > atom.xml
  8. <?xml version="1.0" encoding="UTF-8"?>
  9. <feed xmlns="http://www.w3.org/2005/Atom">
  10. <title>heads.dyne.org news feed</title>
  11. <subtitle type="html">News from the heads libre privacy GNU/Linux distribution</subtitle>
  12. <link href="https://heads.dyne.org/atom.xml" rel="self" />
  13. <link href="https://heads.dyne.org/" />
  14. <id>heads.dyne.org</id>
  15. <updated>$(date --rfc-3339=seconds | tr ' ' 'T')</updated>
  16. EOF
  17. grep '^*' index.html.md | while read line; do
  18. mdpath="$(printf "%s\n" "$line" | mawk -F '[()]' '{print $2}' | sed 's/.html$/.html.md/')"
  19. title="$(printf "%s\n" "$line" | mawk -F '[\[\]]' '{print $2}')"
  20. text="$(sed -e '2,/^$/d' -e '/^$/q' $mdpath | tail -n+2 | tr '\n' ' ')"
  21. date="$(printf "%s\n" "$line" | mawk -F '[()]' '{print $4}')T13:37+01:00"
  22. author="$(cat $mdpath | tail -n1 | mawk -F'[\[\]]' '{print $2}')"
  23. email="$(cat $mdpath | tail -n1 | mawk -F'[(:)]' '{print $3}')"
  24. url="https://heads.dyne.org/$mdpath"
  25. url="$(printf "%s" "$url" | sed 's/.md$/.html/')"
  26. #printf "(*) %s :: by %s (%s)\n" "$title" "$author" "$date"
  27. cat <<EOF >> atom.xml
  28. <entry>
  29. <title type="html" xml:lang="en-US">${title}</title>
  30. <link href="${url}" />
  31. <id>${title}</id>
  32. <updated>${date}</updated>
  33. <content type="text">
  34. ${text}
  35. </content>
  36. <author>
  37. <name>${author}</name>
  38. <email>${email}</email>
  39. </author>
  40. </entry>
  41. EOF
  42. done
  43. printf "</feed>\n" >> atom.xml
  44. sed -i -e 's/[ \t]*$//' atom.xml