#! /bin/bash 
path=/home/joelchrono12/git/joelchrono12.ml/_posts/
title=$(rofi -l 0 -width 50 -p "Title:" -dmenu)
filen=$(echo $title | tr " ,.!" "-"| awk '{print tolower($0)}')
if [ -z $title ]; then
	exit
fi
today=$(date +"%Y-%m-%d")
filename=($today-$filen)
description=$(rofi -l 0 -width 60 -height 20 -p "Description:" -dmenu)
tags=$(rofi -l 0 -width 45 -p "Tags:" -dmenu)
num=0
while [ $num = 0 ]; do
	choice=$(echo -e "Edit file\nEdit title\nEdit description\nEdit tags\nCancel" | rofi -width 15 -l 5-p "Now?:" -dmenu)

	if [[ $choice = "Edit file" ]]; then
  	touch $path/$filename.md
  	echo -e "---\ntitle: $title\nheader: $title\ndescription: $description\ntags: $tags\npermalink: /blog/$filen/\nlayout: post\ndate: $today $(date +"%T") -0500\nhost: fosstodon.org\nusername: joeligj12\ncom_id: idcomments\n---">> $path/$filename.md
		num=1
		alacritty -e nvim $path/$filename.md & disown
        #cp $path/$filename.md ~/Documents
	elif [[ $choice = "Edit title" ]]; then
		title=$(rofi -l 0 -width 50 -p "Title:" -dmenu)
	elif [[ $choice = "Edit description" ]]; then
		description=$(rofi -l 0 -width 60 -height 20 -p "Description:" -dmenu)
	elif [[ $choice = "Edit tags" ]]; then 
		tags=$(rofi -l 0 -width 45 -p "Tags:" -dmenu)
	else
		num=1
	fi
done

