phlog 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. set -e
  3. local="/home/lich/site/"
  4. gopher_location="$local/public_gopher/musings/"
  5. html_location="$local/public_html/musings/"
  6. remote="/home/lich/"
  7. server="dataswamp"
  8. page="dataswamp.org"
  9. sync_command="rsync -aPulK $local/* $server:$remote"
  10. html_processor="markdown"
  11. htmlgen() {
  12. printf "<!DOCTYPE html><html lang=\"en\">\n<head><meta charset=\"utf-8\">\n<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"favicon.ico\" />"
  13. printf "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
  14. printf "<link rel=stylesheet href="../static/css/main.css">\n<title>%s</title>\n" "$(sed -n "3p" $1)"
  15. printf "</head>\n<body>\n<article>\n"
  16. printf "<p><small><em>%s</em></small></p>" "$(date -d$2 -R)"
  17. sed -n '3,$p' "$1" | $html_processor
  18. printf "</article><p><small><a href="index.html">Back to the index</a></small></p></body></html>"
  19. git add "$1"
  20. }
  21. htmlnew() {
  22. {
  23. printf "/tbody\na\n"
  24. printf "<tr><td><a href=\"%s\">%s</a></td></tr>\n.\nw\nq\n" "$2" "$1"
  25. } | ed -s "$html_location/index.html"
  26. git add "$html_location/index.html"
  27. }
  28. atomnew() {
  29. {
  30. printf "10\n"
  31. printf "i\n\n\t<entry>\n"
  32. printf "\t\t<id>%s</id>\n" "$2"
  33. printf "\t\t<title><![CDATA[%s]]></title>\n" "$1"
  34. printf "\t\t<link href=\"%s\" />\n" "$2"
  35. printf "\t\t<content type=\"text\"><![CDATA["
  36. cat "$3"
  37. printf "]]></content>\n"
  38. printf "\t\t<updated>%s</updated>\n" "$4"
  39. printf "\t</entry>\n.\nw\nq\n"
  40. } | ed -s "$5"
  41. git add "$5"
  42. }
  43. gophernew() {
  44. {
  45. printf "/MUSINGS\n+2\n"
  46. printf "i\n[0|%s|%s|%s|70]\n.\nw\nq\n" "$1" "$2" "$3"
  47. } | ed -s "$gopher_location/../index.gph"
  48. git add "$gopher_location/../index.gph"
  49. }
  50. post() {
  51. date="$(sed '1 s/# //;q' $1)"
  52. title="$(sed '3q;d' $1)"
  53. htmlgen $1 $date > $html_location/${1%md}html
  54. gophernew "$title" "/~lich/musings/$1" "$page"
  55. atomnew "$title" "gopher://$server.org/0/~lich/musings/$1" "$1" "$date" "$gopher_location/../musings.atom.xml"
  56. htmlnew "$title" "${1%md}html"
  57. atomnew "$title" "https://dataswamp.org/~lich/musings/${1%md}html" "$1" "$date" "$html_location/musings.atom.xml"
  58. git commit -m "New post: $1"
  59. $sync_command
  60. }
  61. atom_rev() {
  62. printf "/%s\n" "${1%md}"
  63. printf "+3\n"
  64. printf ".,+%sd\n" "$(cat $gopher_location/$1 | wc -l)"
  65. printf "i\n"
  66. printf "\t\t<content type=\"text\"><![CDATA["
  67. cat "$1"
  68. printf "]]></content>\n.\n\n"
  69. printf "d\n"
  70. printf "i\n"
  71. printf "\t\t<updated>%s</updated>\n.\nw\nq\n" "$date"
  72. }
  73. revise() {
  74. date="$(date -Iseconds)"
  75. atom_rev "$1" | ed -s "$gopher_location/../musings.atom.xml"
  76. atom_rev "$1" | ed -s "$html_location/musings.atom.xml"
  77. git add "$gopher_location/../musings.atom.xml" "$html_location/musings.atom.xml"
  78. htmlgen "$1" "$date" > $html_location/${1%md}html
  79. git commit -m 'Revised $1'
  80. $sync_command
  81. }
  82. case "$1" in
  83. n*) post "$2" ;;
  84. r*) revise "$2" ;;
  85. esac