#!/usr/bin/env zsh # print usage if no title is given if (($#<1)); then print -- "Create a new blog entry setting default parameters such as the date." print -P -- "%BUsage:%b\t$0:t post_title" exit 1 fi cd $0:t/.. root="$PWD" title="$*" # basefilename is the filename where all spaces # were replaced by '-' # and all accentued letter by corresponding ASCII one basefilename="$( print $title | perl -pe 'chomp(); s#ç#c#g; s#àâ#a#g; s#éèê#e#g; s#ô#o#g; s#û#u#g; s#\W#-#g')" # construct the final filename yearmonthday=$( date "+%Y-%m-%d" ) linkname="$root/latest.md" filename="$root/multi/blog/${yearmonthday}-$basefilename.md" [[ ! -d ${filename:h} ]] && mkdir -p ${filename:h} dirname="$root/site/img/blog/${yearmonthday}-${basefilename}" [[ -e $filename ]] && { print -P -- "%BAttention%b : $filename existe déjà." print -P -- "%BError try with a new name%b" exit 3 } # now title and filename are well defined print " title = $title" print "filename = $filename" now=$( date "+%Y-%m-%dT%H:%M:%S+02:00" ) > $filename cat << ENDFORMAT ----- isHidden: false menupriority: 1 kind: article created_at: $now fr: title: $title en: title: $title author_name: Yann Esposito author_uri: yannesposito.com # tags: ----- <%= blogimage("main.png","Title image") %> begindiv(intro) en: <%= tldr %> fr: <%= tlal %> enddiv ENDFORMAT print "imagedir = $dirname" mkdir $dirname ln -sf ./multi/${filename#*/multi/} $linkname vim $linkname