logo

blog

My little blog can’t be this cute!

new_article.sh (1773B)


  1. #!/bin/sh -v
  2. if [ ${#} -lt 1 ]
  3. then
  4. ${ht}echo 'Usage: articles/new.sh Title'
  5. ${ht}exit 1
  6. fi
  7. title="${1}"
  8. title_url="$(echo \"$title\" | jq -r '@uri')"
  9. timestamp="$(date -u +%FT%TZ)"
  10. ht=" "
  11. WORKDIR="$(dirname $0)"
  12. cat >"${WORKDIR}/articles/${title}.shtml" <<-EOF
  13. <!DOCTYPE html>
  14. <html lang="en">
  15. ${ht}<head>
  16. <!--#include file="/templates/head.shtml" -->
  17. ${ht}${ht}<meta property="og:type" content="article"/>
  18. ${ht}${ht}<meta property="og:title" content="${title}"/>
  19. ${ht}${ht}<title>${title} — Cyber-home of lanodan</title>
  20. ${ht}</head>
  21. ${ht}<body>
  22. <!--#include file="/templates/en/nav.shtml" -->
  23. <!--#include file="/articles/${title}.xhtml"-->
  24. ${ht}${ht}<a href="/articles/${title_url}.xhtml">article only(plain XHTML)</a>
  25. <!--#include file="/templates/en/footer.shtml" -->
  26. ${ht}</body>
  27. </html>
  28. EOF
  29. cat >"${WORKDIR}/articles/${title}.xhtml" <<-EOF
  30. <article xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="h-entry">
  31. <a href="/articles/${title_url}"><h1>${title}</h1></a>
  32. <p><a href="">Fediverse post for comments</a>, published on ${timestamp}, last updated on ${timestamp}</p>
  33. </article>
  34. EOF
  35. #TODO: Grep for the id before appending
  36. grep "<id>https://hacktivis.me/articles/${title_url}</id>" \
  37. "${WORKDIR}/feed.atom" || ed "${WORKDIR}/feed.atom" <<-EOF
  38. /new.sh: new articles here/
  39. a
  40. ${ht}<entry>
  41. ${ht}${ht}<title>${title}</title>
  42. ${ht}${ht}<link rel="alternate" type="text/html" href="/articles/${title_url}"/>
  43. ${ht}${ht}<id>https://hacktivis.me/articles/${title_url}</id>
  44. ${ht}${ht}<published>${timestamp}</published>
  45. ${ht}${ht}<updated>${timestamp}</updated>
  46. ${ht}${ht}<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  47. <!--#include file="/articles/${title}.xhtml"-->
  48. ${ht}${ht}</div></content>
  49. ${ht}</entry>
  50. .
  51. wq
  52. EOF