I’m having a problem with HTML codes in my summaries. Basically, Hugo will strip all HTML codes from my text when it generates a summary. This screws up the formatting severely.
Now, I discovered when I place <!--more-->
in my document, manually telling Hugo where to split, it preserves the HTML. Unfortunately, it inserts a paragraph return in my main text, even when one doesn’t exist in the document.
What I’d like is autogenerated summaries which preserve the HTML. Alternatively, a way to include the <!--more-->
without generating a paragraph would be a pain but workable. Ideal would be a way to just strip the <a>
tags from the summaries, since they’re effectively broken.
Any thoughts?
1 Like
I roll my own. Near the top of baseof.html
I include a partial:
{{ partial "functions/set-page-scoped-scratch-vars.html" . }}
This defines several Scratch variables, including pageDescription
. The code in the partial evaluates various things, and then sets and formats pageDescription
accordingly.
Then I use {{ .Scratch.Get "pageDescription" }}
instead of {{ .Summary }}
.
The summary of a page’s content is, in my view, even more important than the page’s title, particularly if it is used in <meta name="description" content="foo">
and microdata. Consequently, I prefer to rely on either .Summary or . Description in a page’s front matter.
I also include a partial at the bottom of baseof.html
:
{{ partial "functions/audit-front-matter.html" . }}
This audits the front matter of every page, and will warnf
or errorf
depending on conditions. For example:
{{/*
Check for missing front matter: description.
Page "kinds" where a description is required: page.
*/}}
{{- if eq .Kind "page" -}}
{{- if lt (countwords .Description) (1) -}}
{{- errorf "(E-1017) Missing front matter (description) in /%s" .Path -}}
{{- end -}}
{{- end -}}