new-article (771B)
1 #!/bin/sh -e 2 3 error() { 4 echo "new-article: $1" >&2; exit 1 5 } 6 7 cd ~/repos/riazj.com/articles 8 9 gitstat="$(git status -s . | grep "^??")" || error "no new articles" 10 article="${gitstat#* }" 11 12 [ "$(printf "%s\n" "$article" | wc -l)" -ne 1 ] && 13 error "found more than one article" 14 15 text2html "$article" 16 grep -q '<meta name="description" content="">' "$article" && 17 error "no article description" 18 19 tidy -mq -wrap --keep-tabs yes --tidy-mark no "$article" 20 21 title="$(grep -im1 "<title>" "$article")" 22 title="${title#*>}"; title="${title% |*}" 23 article="${article%.html}" 24 25 sed -i "/<ul>/a\<li><time datetime=\"$(date +%F)\">$(date +'%Y %b %d')</time>\ 26 <a href=\"/articles/$article\">$title</a></li>" "../index.html" 27 28 git add -A; git commit -m "Write article about $*"; git push