#!/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\