tImproved the post.sh script - monochromatic - monochromatic blog: http://blog.z3bra.org
(HTM) git clone git://z3bra.org/monochromatic
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit 7f5983cd9ddf343e98d74249ee9ca8fbfdde0372
(DIR) parent 72d3b9af102866db14adbd8f8a14d3d1729b18a3
(HTM) Author: z3bra <willy@mailoo.org>
Date: Mon, 3 Feb 2014 11:20:39 +0100
Improved the post.sh script
Diffstat:
M tools/body.template | 4 ++--
M tools/post.sh | 34 +++++++++++++++++++++++--------
M tools/publi.sh | 2 +-
3 files changed, 28 insertions(+), 12 deletions(-)
---
(DIR) diff --git a/tools/body.template b/tools/body.template
t@@ -1,10 +1,10 @@
<div id='wrapper'>
<section>
<h1>
- <a href='#'></a>
+ <a href='#'>BLOG_TITLE</a>
</h1>
<h2>
- —
+ — BLOG_DATE
</h2>
<article>
<p>
(DIR) diff --git a/tools/post.sh b/tools/post.sh
t@@ -1,18 +1,34 @@
#!/bin/bash
-[[ -z "$1" ]] && exit 1
-folder=$(date +%Y/%m)
-file=${1// /-}.html
-[[ ! -d ${folder} ]] && mkdir -p ${folder}
+# Ask the user for a title
+read -p "post title" title
-POST="${folder}/${file}"
+# use post title to name the file
+file=`echo ${title}| sed "s/\s\+/-/g;s/./\l&/g;s/[,.!;\"']/g"`
-cat tools/{head,body,foot}.template >> $POST
+#date format for the post
+date=`date +%d %B, %Y`
-[[ ! -f ${folder}/${file} ]] && echo "cannot create ${POST}" && exit 1
+# The format of the path to the post, here: /yyyy/mm/
+folder=`date +%Y/%m`
-echo "$POST created"
+# create the path if it does not exists
+test -d ${folder} || mkdir -p ${folder}
-ln -fs ${POST} post.html
+# build the whole path
+post="${folder}/${file}"
+
+# use the templates to create the post skeleton
+cat tools/{head,body,foot}.template >> ${post}
+
+# put the title and date in the post
+sed "s/BLOG_TITLE/${title};s/BLOG_DATE/${date}"
+
+test -f ${folder}/${file} || echo "cannot create ${post}" && exit 1
+
+echo "$post created"
+
+# create a symlink to the last post, to easily access it
+ln -fs ${post} last_post.html
(DIR) diff --git a/tools/publi.sh b/tools/publi.sh
t@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# Re-generate the RSS feed
tools/feeds.sh