Inconsistent behavior with .Summary tag

Hugo Static Site Generator v0.51/extended darwin/amd64

I notice that the behavior for .Summary is different depending on how it is initiated. If the user adds a <!--more--> tag to their content, the .Summary is generated in HTML, but if it is automatically generated (by virtue of the fact that the .Summary tag is used) it is generated in plain text.

Because we can’t then add the HTML back into the .Summary tag, this causes inconsistent results on the front-end and makes certain things (like creating a .Content without .Summary tag) impossible unless one just wants all of their content unformatted.

I’m curious to know if this is a technical limitation or a design decision. I couldn’t find any history on this behavior.

I’ve put an example repo up.

It’s been like this since the dawn of day, so you would have to ask Steve about the “why”.

Thank you

To get consistent summary paragraph behavior, try:

{{ if in .RawContent "<!--more-->" }}
  {{ .Summary | safeHTML }}
{{ else }}
  <p>{{ .Summary | safeHTML }}</p>
{{ end }}

But I can speculate: It makes some sense to remove “some HTML” to make the summary listing consistent (possibly images, at least headline tags). With “manual summary” you can control this yourself.

There is the truncate func, which I guess is “smarter”, but I don’t think there is an easy way to check if you have manual summary or not.

I have some plans to revisit this problem at some point not very far into the future. I have talked about “content sections” in some other places.

1 Like

I’ve tried various iterations and hacks and have found none that I think are satisfactory (particularly in conjunction with displaying “content without summary,” which has been brought up in the forums before). I posted this more from the perspective that I think Hugo “should” handle this in the big picture, rather than solving my immediate problem. To that end—though it’s way outside of my league—I’ve been contemplating how I might be able to contribute to a fix on this, which may be more of a torment than a help, but I would like to try.

Thanks. That does not output HTML.

Ah, I see now that it only adds the surrounding <p> tags, but does nothing to inner HTML.

1 Like