diff options
author | Matthew Lemon <y@yulqen.org> | 2023-04-19 09:46:43 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2023-04-19 09:46:43 +0100 |
commit | 5df453d3cfddf0aa410f8d41b7cc78f780973bdc (patch) | |
tree | e3c1528f7f89d1eac86094582edc0fb1584d277e /bashrc | |
parent | b43a6b4a28d0c564d7e663cd43b9ee73a0b110fd (diff) |
Adds a bash function to create a new blog post in Hugo
This function is documented but I used ChatGPT to assist with the awk
and sed subsitutions. The sed suggestions took a while to get right and
eventually it resorted to using awk. Works though.
Diffstat (limited to '')
-rw-r--r-- | bashrc | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -38,6 +38,7 @@ alias h='hey_openai' alias hd='openai_data' alias xclip='xclip -selection c' alias notes="cd ~/Documents/Notes/" +alias blog="cd ~/code/html/yulqen.org/" alias bud="cd ~/Documents/Budget/ledger/hledger/" alias getip="curl ifconfig.me" alias tprojects="task rc.list.all.projects=1 projects" @@ -74,6 +75,28 @@ complete -o default -o nospace -F _todo t # Functions +############################################################## +# Quick way to create a new blog post with Hugo from wherever +# on the filesystem. +# Used ChatGPT to get the substitution and escaping correct. +# Called with a single string argument. +# ############################################################ + +function newpost() { + if [[ $# -ne 1 ]]; then echo "Give me the title!"; return; fi + title="$1" + # convert title to lowercase and replace spaces with hyphens for the slug + slug=$(echo "$title" | tr '[:upper:]' '[:lower:]' | tr ' ' '-') + # create the new post file with Hugo + cd $HOME/code/html/yulqen.org + post_path="content/blog/$slug.md" + hugo new "$post_path" + # update the front matter with the original title string + echo "Looking for $post_path..." + awk -v title="$title" '{gsub(/title: .*/, "title: \""title"\"")}1' "$post_path" > tmp && mv tmp "$post_path" + vim $post_path +} + ################################################################### # To output in cat, just call todj. # To enable editing the files in vim, call todj vim. |