dotfiles

configurations and scripts
git clone https://riazj.com/git/dotfiles
Log | Files | Refs | LICENSE

new-article (739B)


      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 .)"
     10 [ -z "$gitstat" ] && error "no new articles"
     11 
     12 article="${gitstat#* }"
     13 [ "$(printf "%s\n" "$article" | wc -l)" -ne 1 ] &&
     14   error "found more than one article"
     15 
     16 grep -q '<meta name="description" content="">' "$article" &&
     17   error "no article description"
     18 
     19 tidy -mq -wrap --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