index.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2017 Alyssa Rosenzweig <alyssa@rosenzweig.io>
  4. # Copyright (C) 2017 Michael Reed <michael@michaelreed.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. BLOGTITLE="Libreboot News"
  19. BLOGBASE="https://libreboot.org/"
  20. BLOGDESCRIPTION="News on Libreboot development"
  21. # MANIFEST determines the order of news articles in news/index.md
  22. FILES=$(< news/MANIFEST)
  23. # usage: title file
  24. title() {
  25. sed -n 1p "$1" | sed -e s-^..--
  26. }
  27. # usage: meta file
  28. meta() {
  29. file=$1
  30. URL=$(printf '%s\n' "${file%.md}.html" | sed -e s-news/--)
  31. printf '%s\n' "[$(title "$file")]($URL){.title}"
  32. printf '%s\n' "[$(sed -n 3p "$file" | sed -e s-^..--)]{.date}"
  33. printf '\n'
  34. printf '\n'
  35. }
  36. # usage: rss_header
  37. rss_header() {
  38. printf '%s\n' '<rss version="2.0">'
  39. printf '%s\n' '<channel>'
  40. printf '%s\n' "<title>$BLOGTITLE</title>"
  41. printf '%s\n' "<link>${BLOGBASE}news/</link>"
  42. printf '%s\n' "<description>$BLOGDESCRIPTION</description>"
  43. }
  44. # usage: rss_main file
  45. rss_main() {
  46. file=$1
  47. # render content and escape
  48. desc=$(sed -e 's/</\&lt;/g' "${file%.md}.bare.html" | sed -e 's/>/\&gt;/g')
  49. url="${file%.md}.html"
  50. printf '%s\n' '<item>'
  51. printf '%s\n' "<title>$(title "$file")</title>"
  52. printf '%s\n' "<link>$BLOGBASE$url</link>"
  53. printf '%s\n' "<description>$desc</description>"
  54. printf '%s\n' '</item>'
  55. }
  56. # usage: rss_footer
  57. rss_footer() {
  58. printf '%s\n' '</channel>'
  59. printf '%s\n' '</rss>'
  60. }
  61. # generate the index file
  62. cat news-list.md > news/index.md
  63. for f in $FILES
  64. do
  65. meta "$f" >> news/index.md
  66. done
  67. # generate the RSS index
  68. rss_header > news/feed.xml
  69. for f in $FILES
  70. do
  71. rss_main "$f" >> news/feed.xml
  72. done
  73. rss_footer >> news/feed.xml
  74. cp news/feed.xml feed.xml