From 9d2c650d7cadf57ecef3d5a1d39f5f98e298ec64 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Mon, 9 Nov 2020 17:39:05 +0100 Subject: Trying to DRY the html with templates --- generate | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 generate (limited to 'generate') diff --git a/generate b/generate new file mode 100755 index 0000000..725d38e --- /dev/null +++ b/generate @@ -0,0 +1,42 @@ +#!/bin/sh + +# Put your posts in a blog_src directory +# Depends on pandoc for markdown to html convertion + +blog_dir=blog + +[ ! -d "$blog_dir" ] || [ -z "$(ls $blog_dir)" ] && exit 1 +mkdir -p "$blog_dir" + +for post_path in "$blog_dir"/*.md +do + post_dst_path=$(echo "$post_path" | sed 's/\.md/.build.html/') + + # Convert markdown post to html + tmp_file=$(mktemp) + pandoc -f markdown -t html < "$post_path" > "$tmp_file" + + ejs base.ejs -i "{\"pageFilename\": \"$post_path\" }" > "$post_dst_path" + + # Put the blog content in a wrapper template + # sed "// r $tmp_file" < blog.template.html > "$post_dst_path" + + # Add blog artcle link to the index.html + title=$(grep '^# .*$' -m 1 "$post_path" | cut -c 2-) + [ -z "$title" ] && echo "post $post_path doesn't have a title" && title=$post_path + + sed -i'' "// a\ +
  • $title
  • " index.html + + echo "Generated post at $post_dst_path" +done + +for util_path in utils/* +do + title=$(basename "$util_path" | tr '_' ' ') + + ejs base.ejs -i "{\"pageFilename\": \"$post_path\" }" > "$post_dst_path" + + sed -i'' "// a\ +
  • $title
  • " index.html +done -- cgit