Script to Create Hugo Post

| posted in: hugo 

When I was using Jekyll to build and deploy this site, I had a Rakefile setup that let me perform a number of common tasks. By typing rake <action>, where action was draft or publish or deploy, I could create a new post, publish a draft, or deploy the site to my web host.

I want to have the same kind of ease with Hugo. As a first step I have created a small Bash script that creates a new post and then opens it in my editor.

Here’s the script.

function hnew() {
    # replace alphanumeric words with a dash, compress repeated dashes to a single
    # dash, replace capital letters with lower case
    post=$(echo $str | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z
    hugo new posts/$post
    nvim content/posts/$post

Once the post has been created, it is opened in Neovim, ready to be edited.

Author's profile picture

Mark H. Nichols

I am a husband, cellist, code prole, nerd, technologist, and all around good guy living and working in fly-over country. You should follow me on Twitter.