More Hugo automation
I publish my blog via https://github.com and Netlify. I've been using Magit to do the heavy lifting of getting my stuff off my PC and onto github. But it's a bit tidious. I really want one command to do it all.
So, I started off with an elisp function:
(setq hugo-base-dir (concat ps-2nd-home-dir "Code/Websites-source/petersmith/")
hugo-buffer "*hugo*")
(defun hugo-publish ()
(interactive)
(setq ps/commit-message (read-from-minibuffer "Commit message: "))
(let* ((default-directory (concat (expand-file-name hugo-base-dir) "/")))
(when (call-process "bash" nil hugo-buffer t "-c" (concat "./Commit.sh " ps/commit-message))
(message "Blog published"))))
which calls my shell script Commit.sh
#!/bin/bash
#
DESCRIPTION="${@:-"A new post"}"
echo "The commit message is: " \"${DESCRIPTION}\"
echo "The working directory is :" `pwd`
git add . && \
git add -u && \
git commit -m "${DESCRIPTION}" && \
git push origin master
That hardest part was escaping the DESCRIPTION
variable.