logo

blog

My website can't be that messy, right? git clone https://anongit.hacktivis.me/git/blog.git/

new_article.sh (1530B)


  1. #!/bin/sh
  2. case $# in
  3. 1)
  4. title="${1}"
  5. file="${1}"
  6. ;;
  7. 2)
  8. title="${2}"
  9. file="${1}"
  10. ;;
  11. *)
  12. echo 'Usage: new_article.sh [filename] <title>'
  13. exit 1
  14. ;;
  15. esac
  16. file_url="articles/$(echo \"$file\" | jq -r '@uri')"
  17. timestamp="$(date -u +%FT%TZ)"
  18. ht=" "
  19. WORKDIR="$(dirname $0)"
  20. if grep -q -F "/articles/${file}" "${WORKDIR}/feed.atom.in"
  21. then
  22. echo 'new_article: error: article already in feed.atom.in'
  23. exit 1
  24. else
  25. ed "${WORKDIR}/feed.atom.in" <<-EOF
  26. /new.sh: new articles here/
  27. a
  28. <xi:include href="${file_url}.xml"/>
  29. .
  30. w
  31. q
  32. EOF
  33. fi
  34. if grep -q -F "/articles/${file}" "${WORKDIR}/home.shtml"
  35. then
  36. echo 'new_article: error: article already in home.shtml'
  37. exit 1
  38. else
  39. ed "${WORKDIR}/home.shtml" <<-EOF
  40. /new.sh: new articles here/
  41. a
  42. <li>$(date -u +%F): <a href="/${file_url}">${title}</a></li>
  43. .
  44. w
  45. q
  46. EOF
  47. fi
  48. cat >"${WORKDIR}/articles/${file}.xml" <<-EOF
  49. <entry>
  50. <title>${title}</title>
  51. <link rel="alternate" type="text/html" href="https://hacktivis.me/${file_url}"/>
  52. <id>https://hacktivis.me/${file_url}</id>
  53. <published>${timestamp}</published>
  54. <updated>${timestamp}</updated>
  55. <!--
  56. <link rel="external replies" type="application/activity+json" href="https://queer.hacktivis.me/objects/50be9d37-dee6-4c69-818e-013fa3b010d0" />
  57. <link rel="external replies" type="text/html" href="https://queer.hacktivis.me/objects/50be9d37-dee6-4c69-818e-013fa3b010d0" />
  58. -->
  59. <content type="xhtml">
  60. <div xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="h-entry">
  61. <!-- Article content goes here -->
  62. </div>
  63. </content>
  64. </entry>
  65. EOF