#!/bin/bash

if [ $# -lt 1 ]; then
    echo "usage: generate_markdown FILE"
    exit 1
fi

file="$1"
file="${file%.*}"  # remove the extension

[ -e "$file.html" ] && chmod +w "$file.html"
(echo '
    <!-- generated from markdown -->
    <html>
    <head>
        <meta charset="utf-8"/>
        <link rel="stylesheet"
            href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
            integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
            crossorigin="anonymous" />
    </head>
    <body style="padding: 0 15px">
' && markdown.pl "$file.md") > "$file.html"
chmod -w "$file.html"

