Hugo .Summary Customization

In my article on supporting link posts in Hugo, I went on a short tangent about the Hugo .Summary function and the fact that I wasn’t using it, but was instead piping .Content to the truncate function.

Mainly I wasn’t using .Summary because it basically strips out the html paragraph tags and makes a big block of text. I find this an interesting choice, because who does this? No one, that’s who. Everyone who uses summaries wants legible summaries, including paragraph breaks. Hugo summaries make the assumption that a handful of words will be enough to draw your readers in, and that that’s the look you want in the first place.

Hugo does provide for overriding this by putting a summary in front matter, but that seems like a major kludge considering how easy it would be for .Summary to take a few option parameters.

In the end, I found that I could use .Summary by setting summaryLength in config.toml and then replacing “\n” in the text replaced by .Summary with two html break tags and piping that to safeHTML.

<div>
		{{ replace .Summary "\n" "<br /><br />" | safeHTML }}
		{{ if .Truncated }}
		<br /><br /><i>(<a href="{{ .RelPermalink }}">Read More</a>)</i>
		{{ end }}
		{{- if .Params.linkurl -}}<br /><br /><a href="{{ .RelPermalink }}"><i class="fas fa-level-down-alt fa-xs"></i>&ensp;Permalink</a>{{- end -}}
</div>

This gives me the summary and truncation style you now see on the home page of this site and on the blog main page.

The funniest thing about some of Hugo’s weird default choices is the scathing tone the angry Hugo guy in the Hugo discourse uses to cut people down when they mention that maybe normal humans like to have nice looking web pages.