scratch/tasks/new_blog_entry

79 lines
1.7 KiB
Text
Raw Permalink Normal View History

#!/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="$*"
2011-05-18 11:13:59 +00:00
# CONFIG
2011-11-04 13:44:29 +00:00
blog_dir="multi/blog"
image_blog_dir="./output/Scratch/img/blog"
2011-05-18 11:13:59 +00:00
# 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
2011-09-30 12:23:27 +00:00
linkname="$root/latest.ymd"
2011-05-18 13:07:18 +00:00
imglinkname="$root/img_latest_blog_dir"
2011-05-18 11:13:59 +00:00
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}
2011-05-18 11:13:59 +00:00
imgdirname="$image_blog_dir/$blogname"
[[ -e $filename ]] && {
2011-05-18 11:13:59 +00:00
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
2011-05-18 13:07:18 +00:00
fr: title: $title
author_name: Yann Esposito
author_uri: yannesposito.com
2013-01-02 15:55:47 +00:00
layout: article2
# tags:
-----
2010-10-26 14:40:05 +00:00
<%= blogimage("main.png","Title image") %>
2010-10-06 14:48:00 +00:00
begindiv(intro)
en: <%= tldr %>
fr: <%= tlal %>
enddiv
ENDFORMAT
2011-05-18 11:13:59 +00:00
print "imagedir = $imgdirname"
mkdir $imgdirname
2011-11-17 10:15:58 +00:00
ln -sf $filename $linkname
2012-05-03 13:13:55 +00:00
[[ -e $imglinkname ]] && \rm $imglinkname
2011-06-07 10:03:06 +00:00
ln -sf $imgdirname $imglinkname
vim $linkname