#!/bin/sh base_template () { body_file=$(mktemp) cat > "$body_file" sed '//r '"$body_file" base.template.html } base_template_link () { link_href="$1" case $link_href in *.css) link_rel="stylesheet" link_type="text/css" ;; *.png) link_rel="icon" link_type="image/png" ;; *) echo Invalid link file exit 1 ;; esac sed "//i\ " } # Setup blog_path=blog mkdir -p "$blog_path" base_template < index.template.html | base_template_link 'favicon.png' | base_template_link 'style.css' > index.html base_template < school.template.html | base_template_link 'favicon.png' | base_template_link 'style.css' > school.html # Generate blog posts for post_path in "$blog_path"/*.md do post_dst_path=$(echo "$post_path" | sed 's_.md_.html_') pandoc -f markdown -t html < "$post_path" | base_template | base_template_link '../favicon.png' | base_template_link '../style.css' > "$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\