local/bin/blo.sh

   1 #!/bin/bash
   2 
   3 post=$(mktemp).md
   4 path=~/Projects/lexa.by/bloge/2018
   5 news=$path/news.txt
   6 
   7 [[ $1 ]] &&
   8 sed "$1q;d" $news | sed 's/\\n/\n/g' |
   9 pandoc -f html -o $post ||
  10 date +'%F %T|' > $post
  11 
  12 cp $post $post.orig
  13 ${EDITOR:-vim} $post
  14 diff $post* && exit
  15 
  16 date=$(sed 1q $post)
  17 body=$(sed 1d $post | pandoc -St html5)
  18 body=$(sed 's/“/«/g' <<< "$body" | sed 's/”/»/g')
  19 body=${body//$'\n'/\\\\n}
  20 
  21 sed -i "${1:-$}a\\$date$body" $news
  22 [[ $1 ]] && sed -i $1d $news
  23 
  24 php $path/../build.php
  25 rm $post*
  26