PeterSmith.Org

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.


    Webmentions
    If you webmention this page, please let me know the URL of your page.

    BTW: Your webmention won't show up until I next "build" my site.

    Word count: 200 (about 1 minutes)

    Published:

    Updated: 7 Jun '21 16:48

    Author: Peter Smith

    Permalink: https://petersmith.org/blog/2021/06/07/more-hugo-automation/

    Section: blog

    Kind: page

    Bundle type: leaf

    Source: blog/2021/06/07/more-hugo-automation/index.org