1 #!/bin/bash
   2 
   3 cd ~/Projects/lexa.by/bloge
   4 
   5 post=$(mktemp -u).md
   6 news=$(date +%Y)/news.txt
   7 
   8 [[ $@ == *-l* || $@ == *--list* ]] &&
   9 awk -F \| '{ print NR ". #" $2 " " substr($3, 1, 20) }' $news &&
  10 exit
  11 
  12 [[ $1 ]] &&
  13 sed 's/\\n/\n/g; '$1'q; d' $news |
  14 pandoc -f html -o $post ||
  15 date +'%F %H:%M||' > $post
  16 
  17 cp $post $post.orig
  18 ${EDITOR:-vim} $post
  19 diff $post* && exit
  20 
  21 meta=$(sed 1q $post)
  22 body=$(sed 1d $post | pandoc -St html5)
  23 body=$(sed 'y/“‘’”/«„“»/' <<< "$body")
  24 body=${body//$'\n'/\\\\n}
  25 
  26 sed -i "${1:-$}a\\$meta$body" $news
  27 [[ $1 ]] && sed -i $1d $news
  28 
  29 ./build.php