As promised, I have created a working bash script for my blog workflow. This makes my entire workflow very efficient and fun!
This is my entire bash script:
#!/bin/bash
blogdir=~/blog
newpost() {
read -p "Enter post filename: " post_filename
hugo_post=content/posts/$post_filename.md
cd $blogdir
hugo new $hugo_post
nvim $hugo_post -c :NoNeckPain
}
publish_post() {
read -p "Enter commit message: " commit_message
gh_main=~/blog-gh/main/
gh_pages=~/blog-gh/ghpages/
cd $blogdir
hugo -d $gh_main
hugo -d $gh_pages
echo -e '\n'
# commit and push to main branch
cd $gh_main
echo "-------Main Branch-------"
git add .
git commit -m "$commit_message"
git push
echo -e '\n'
# commit and push to gh-pages branch
cd $gh_pages
echo "-------gh-pages Branch-------"
git add .
git commit -m "$commit_message"
git push
echo "-----------------------------"
echo -e '\n'
if [[ $? -eq 0 ]]
then
echo "Blog published."
echo -e '\n'
else
echo "Push unsuccessful."
echo -e '\n'
fi
}
case $1 in
new)
newpost
;;
publish)
publish_post
;;
"")
# If no parameter is provided, hugo will
# serve existing blog iteration at localhost:1313
cd ~/blog/
hugo serve
;;
*)
echo "Invalid parameter."
;;
esac
I had a lot of fun in researching and making this. Now I wonder what else can I automate..
By the way, this post is posted using this very script: