new-article (750B)
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 grep -q '<meta name="description" content="">' "$article" && 16 error "no article description" 17 18 tidy -mq -wrap --keep-tabs yes --tidy-mark no "$article" 19 20 title="$(grep -im1 "<title>" "$article")" 21 title="${title#*>}"; title="${title% |*}" 22 article="${article%.html}" 23 24 sed -i "/<ul>/a\<li><time datetime=\"$(date +%F)\">$(date +'%Y %b %d')</time>\ 25 <a href=\"/articles/$article\">$title</a></li>" "../index.html" 26 27 git add -A; git commit -m "Write article about $*"; git push