Skip to main content
nevstokes.com

Super Styling

Monday, May 4, 2020

2 minutes

The wisdom of the wise, and the experience of ages, may be preserved by quotation.
— Issac D'Israeli

I liked to begin posts on the previous incarnation of this blog with a quotation and I see no reason why I shouldn’t continue the practice. For one thing, I quite enjoy researching them – occasionally stumbling over misattribution and misunderstanding when attempting to verify.

For example, Gandhi’s purported “Be the Change”, Michaleangelo’s “Ancaro Imparo” and the history of considering oneself a Citizen of the World – a phrase that was thrust into the headlines most recently when Theresa May put forward her own unpleasant interpretation.

Anyway, in order to avoid repetition in my Markdown source files, this use case seemed to be a prime candidate for writing my first custom Hugo shortcode.

Consequently, I’ve added this to the top of my blog post archetype:

1
{‚Äč{< quote text="..." author="..." >}}

Which makes use of the corresponding shortcode template:

layouts/shortcodes/quote.html

1
2
3
4
5
6
<figure>
    <blockquote>{{ .Get "text" }}</blockquote>
    <figcaption>
        &mdash; {{ .Get "author" | safeHTML }}
    </figcaption>
< /figure>
  1. Passing the author through the safeHTML function lets me add arbitrary markup, should I wish to include a citation for example.

With some styling applied, I get a nice-looking introduction for each post with minimal effort and a single file to change should I ever feel the need to update the layout.

#blog