#!/bin/bash

set -eux

TODAY="$(date +'%Y%m%d')"
DATETIME="$(date +'%F %H:%M')"
PUBDATE="$(date +'%F %H:%M %Z')"
TITLE="$@"
if [ -z "$TITLE" ]
then
	TITLE="${TODAY}"
	SLUG="${TITLE}"
else
	TITLE="$@"
	SLUG="$(echo ${TITLE}|tr [A-Z] [a-z]|tr ' ' '-')"
fi

POSTPATH="content/posts/${SLUG}.md"
if [ ! -e "${POSTPATH}" ]
then
	cat <<EOF > ${POSTPATH}
Title: ${TITLE}
Slug: ${SLUG}
Date: $(date +'%F')
Modified: $(date +'%F')
Category: 
Tags: 
Authors: kyle
Summary: 
EOF
else
	sed -i -e "s/Modified: .*$/Modified: ${PUBDATE}/" $POSTPATH
fi


#EDITOR="$(command -v em)"

EDITOR="${EDITOR:-gvim}"
$EDITOR $POSTPATH
