diff options
-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. |