Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #!/bin/sh
  2. local="/home/lich/site/"
  3. gopher_location="$local/public_gopher/musings/"
  4. html_location="$local/public_html/musings/"
  5. remote="/home/lich/"
  6. server="dataswamp"
  7. page="dataswamp.org"
  8. sync_command="rsync -aPuK $local/* $server:$remote"
  9. html_processor="pandoc"
  10.  
  11. htmlgen() {
  12. printf "<!DOCTYPE html><html lang=\"en\">\n<head><meta charset=\"utf-8\">\n"
  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. }
  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. }
  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. }
  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. }
  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. $sync_command
  59. }
  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.  
  74. revise() {
  75. date="$(date -Iseconds)"
  76. atom_rev "$1" | ed -s "$gopher_location/../musings.atom.xml"
  77. atom_rev "$1" | ed -s "$html_location/musings.atom.xml"
  78. htmlgen "$1" "$date" > $html_location/${1%md}html
  79. $sync_command
  80. }
  81.  
  82. case "$1" in
  83. n*) post "$2" ;;
  84. r*) revise "$2" ;;
  85. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement