aboutsummaryrefslogtreecommitdiff
path: root/generate-blog
diff options
context:
space:
mode:
Diffstat (limited to 'generate-blog')
-rwxr-xr-xgenerate-blog29
1 files changed, 29 insertions, 0 deletions
diff --git a/generate-blog b/generate-blog
new file mode 100755
index 0000000..8694b74
--- /dev/null
+++ b/generate-blog
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# Put your articles in a blog_src directory
+# Depends on pandoc for markdown to html convertion
+
+[ ! -d blog_src ] || [ -z $(ls blog_src) ] && exit 1
+mkdir -p blog
+
+cp -vf index.template.html index.html
+rm -vf blog/*
+
+for article_path in blog_src/*.md
+do
+ article_dst_path=$(echo "$article_path" | sed 's/blog_src/blog/' | sed 's/\.md/.html/')
+
+ # Convert markdown article to html
+ tmp_file=$(mktemp)
+ pandoc -f markdown -t html < "$article_path" > "$tmp_file"
+ # Put the blog content in a wrapper template
+ sed "/<!--BLOG-->/ r $tmp_file" < blog.template.html > "$article_dst_path"
+
+ # Add blog artcle link to the index.html
+ title=$(grep '^# .*$' -m 1 "$article_path" | cut -c 2-)
+ [ -z "$title" ] && echo "Article $article_path doesn't have a title" && title=$article_path
+ sed -i'' "/<!--BLOGINDEX-->/ a\
+ <li><a href=\"$article_dst_path\">$title</a></li>" index.html
+
+ echo "Generated article at $article_dst_path"
+done