scratch/tasks/new_blog_entry
2013-01-02 16:55:47 +01:00

78 lines
1.7 KiB
Bash
Executable file

#!/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="$*"
# CONFIG
blog_dir="multi/blog"
image_blog_dir="./output/Scratch/img/blog"
# 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
linkname="$root/latest.ymd"
imglinkname="$root/img_latest_blog_dir"
blogname="$basefilename"
# Uncomment if you prefer use date-title name for url
# yearmonthday=$( date "+%Y-%m-%d" )
#
# blogname="${yearmonthday}-$basefilename"
filename="$blog_dir/$blogname.md"
# create directory if doesn't exists
[[ ! -d ${filename:h} ]] && mkdir -p ${filename:h}
imgdirname="$image_blog_dir/$blogname"
[[ -e $filename ]] && {
print -P -- "%BError%b $filename already exists. Try with another name."
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
en: title: $title
fr: title: $title
author_name: Yann Esposito
author_uri: yannesposito.com
layout: article2
# tags:
-----
<%= blogimage("main.png","Title image") %>
begindiv(intro)
en: <%= tldr %>
fr: <%= tlal %>
enddiv
ENDFORMAT
print "imagedir = $imgdirname"
mkdir $imgdirname
ln -sf $filename $linkname
[[ -e $imglinkname ]] && \rm $imglinkname
ln -sf $imgdirname $imglinkname
vim $linkname