logo

blog

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

new_article.sh (1207B)


  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: articles/new.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 "/articles/${file}" 'feed.atom.in'
  21. then
  22. echo '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. cat >"${WORKDIR}/articles/${file}.xml" <<-EOF
  35. <entry>
  36. <title>${title}</title>
  37. <link rel="alternate" type="text/html" href="/${file_url}"/>
  38. <id>https://hacktivis.me/${file_url}</id>
  39. <published>${timestamp}</published>
  40. <updated>${timestamp}</updated>
  41. <!--
  42. <link rel="external replies" type="application/activity+json" href="https://queer.hacktivis.me/objects/50be9d37-dee6-4c69-818e-013fa3b010d0" />
  43. <link rel="external replies" type="text/html" href="https://queer.hacktivis.me/objects/50be9d37-dee6-4c69-818e-013fa3b010d0" />
  44. -->
  45. <content type="xhtml">
  46. <div xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="h-entry">
  47. <!-- Article content goes here -->
  48. </div>
  49. </content>
  50. </entry>
  51. EOF