Posting with iOS Shortcuts
I came up with a shortcut that lets me post to this blog quickly from my phone. I didn’t want it to be too involved, with a lot of prompts for tags and categories, etc… more like posting to Twitter. One thing I wanted to be able to do was include hashtags in the post and have those be automatically converted into Hugo tags, ideally clickable within the post too.
To do this I use a matching block in shortcuts to find all the words starting with #
, then build the tag list and add that to the front matter of the post. That converts the hashtags into Hugo tags.
To make the hashtags clickable though, I needed to do a search and replace, converting all the hashtags into links. That was easy enough, but I didn’t want to hardcode the domain since sometimes I’m running Hugo on my localhost and having the domain hardcoded would take me off the local instance and to the live site.
Turns out Hugo has a shortcode to get URLs for various places on your site. Originally I thought I could use it to link directly to the tags/tagname
URL, but this shortcode appears to only work with the static pages on your site, not the categories or tags. This is what I ended up doing in the search and replace:
Replace: #(\w)*
With: [#$1]({{< ref "/" >}}tags/$1)
Using the ref
shortcode on /
generates a baseURL for wherever you’re site is running, then I simply append the tags/tagname
to get the URL to the tag page. Works like a charm.