#!/bin/sh
# generate a base blog file

printf "Enter name of blog entry: "
read -r name
filename="$(echo "$name" | sed 's/ /-/g')"

# make sure we don't overwrite an existing file
if [ -f "$filename" ]; then
  printf "Blog entry already exists! Please choose a different name.\n"
  exit 1
fi

mkdir "$filename"
cat > "$filename/index.html" << EOF
<!DOCTYPE HTML>
<html lang="en">
  <title>'$name'</title>
  <meta name="date" content="$(date "+%Y/%m/%d")">
  <link rel="stylesheet" href="/style.css">
  <body id="blog">
    <p>
    </p>
  </body>
</html>
EOF
[ "$EDITOR" ] && $EDITOR "$filename/index.html" || vim "$filename/index.html"

echo "Make sure to run sup to add to rss feed!"
