Custom shortcodes
I’ve known about custom shortcodes in Hugo for awhile, but I’ve never had the need to use them.
Now that I’m taking part in 100DaysToOffload, it makes sense to create one, because it makes it less cumbersome to write posts. I only have to make changes to one file to update copy across all of my related posts.
The implementation is concise, you create a new HTML file in layouts/shortcodes
, for example:
<!--100daystooffload.html-->
This is post number {{ $.Page.Params.sequence }} in my [100 Days To Offload](https://100daystooffload.com/) challenge.
[View all posts](/tags/100daystooffload/) or [subscribe via RSS](/tags/100daystooffload/index.xml).
---
Then you can refer to the shortcode in your posts using the filename excluding the extension:
{{% 100daystooffload %}}
The reference to $.Page.Params.sequence
is replaced with the sequence
variable defined in the frontmatter for the post. For each new post I write, I manually set the sequence
accordingly. This post, for instance, is number 4.
On the web
📝 10 April 2025 at 15:37 - I decided to cancel my pre-order of the new frameworkcomputer...
Thu Apr 10 2025 by Kev QuirkBlogging expectations
Wed Apr 9 2025 by Joel's Log FilesInstalling NPM Packages Very Quickly
Tue Mar 25 2025 by Andrew Healey's BlogDoing in-place, single-node Postgres upgrades with almost no downtime
Sun Mar 2 2025 by Stan's blogIntroducing laravel-tfa-confirmation
Sun Feb 2 2025 by stefanzweifel.dev
Generated by openring