Skip to main content

Pretty Good Hat

Tag: code

Recent chat around about enabling an “on this day” plugin prompted me to put together the shortcode below. Unlike sophisticated hugo configurations, mine is just updated by a cron job, so I can render it statically, without any javascript, and it’s always current to the day, even if I haven’t posted that day.

I call this shortcode from my /now page:

Posts on this day ({{ now.Format "Jan 2" }}):
{{ range (where .Site.RegularPages "Section" "in" (slice "post" "note")) }}
  {{ if eq .Date.YearDay now.YearDay}}
  <li><a href="{{ .Permalink }}">{{ .Date.Format "2006-01-02"}} / {{ .Title }}</a>
{{ else }}
    <li>... no entries ... 
{{ end }}

Hugo: render hooks and partial for displaying images

Markdown render hooks allow for adding customization to the default markdown to html rendering in hugo. When placed in _default/_markup/render-image.html, this example overrides the standard rendering of images from markdown to include a call to Glightbox.

    <a href="{{ .Destination | safeURL }}" class="glightbox" data-gallery="{{ .Page.Permalink }}">
    <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" style="max-height: 720px" />

This grabs the page’s permalink for the data-gallery property.

For photos specified in a post’s yaml frontmatter, I call a partial in my article template, photos.html:

    {{ range }}  
    <a href="{{ replace .value " " "" }}" class="glightbox" 
            data-gallery="{{ replace .value " " "" }}">
    <img src="{{ replace .value " " "" }}" alt="{{ .alt }} "
    style="max-height: 720px;"  />
    {{ end }}

Both of these assign the data-gallery property in order to avoid overlapping galleries on index or other pages with multiple posts. One future improvement to try is building a shortcode to replace the partial, so that the gallery ID or other properties can be customized at call time.

a colorful clock-like diagram showing a high amount of listening time over the years between about 8 am and 10 pm. The other angles of the clock are empty.

Today’s experiment with my data is this clock-like display of my peak listening hours across time. All of these would be really fun to integrate into more Shiny-based toys – maybe that will be next on my list.

Adding Todoist items with an Alfred workflow

I've long had a workflow in Alfred for adding things to my grocery list in Wunderlist. With Wunderlist being retired, I've switched a couple of shared-with-family lists to Todoist, and it's mostly okay; Todoist is much less of a good tool for just making lists, as it's oriented to projects  and lifestyle methodologies, but is good enough for what we need right now.

So I re-built my workflow in Alfred! All you need is a workflow that runs a bash script, and use the following for the code:

  curl \
  -d token=YOUR_TOKEN \
  -d commands="[{\"type\": \"item_add\", \"temp_id\": \"$(uuidgen)\", 
	    \"uuid\": \"$(uuidgen)\", \"args\": {\"content\": \"{query}\", \"project_id\": OPTIONAL}}]"

YOUR_TOKEN is found on the settings -> integrations page of your Todoist account. Specify a project ID if desired (I use the ID of my 'groceries' list as a default here). Otherwise omit the project argument. You can find the project ID by viewing the project in your browser; it will have a URL like, where the 123456789 is your project's ID.