#!/bin/sh

# Editable variables. Change to your liking
BLOG_PATH="$HOME/proj/hugo/elpengu"
[ -z $EDITOR ] && EDITOR="vim"

# Edit a blog post. If given post does not exist, create one.
edit() {
	[ -z $1 ] && echo "You need to provide a blog title." && exit 1
	
	POST_PATH="$BLOG_PATH/content/posts/${1}.md"
	[ -f "$POST_PATH" ] && eval $EDITOR "$POST_PATH" && exit 0
	
	cd "$BLOG_PATH"
	hugo new "posts/${1}.md"
	eval $EDITOR "$POST_PATH"
}

publish() {
	echo test
}

remove() {
	echo test1
}

[ -z $1 ] && echo "Please choose between [edit | publish | remove]." && exit 1

case $(echo $1 | tr '[:upper:]' '[:lower:]') in
	"edit")
		edit "$2"
		;;
	"publish")
		publish "$2"
		;;
	"remove")
		remove "$2"
	*)
		echo "Invalid option. Please choose between [edit | publish | remove]." && exit 1
		;;
esac
