How is `.Summary` generated?

In theme I am using there is:

<section class="post-excerpt">
   {{ .Summary }}
</section>

The above works if I have a summary field in the front matter section. But if I have a <!--more--> in the post content, it breaks in two ways:

  1. The .summary in the front matter is no longer considered, which I would like to consider always if provided.
  2. At the bottom of a post, there is a section with card like elements to go to the previous or the next post with summary display. If <!--more--> is provided in those posts, not only does the summary in the card does not use the summary field but the rendering also gets messed up. Because anything above <!--more--> gets inserted as <p> and so the styles on paragraph get applied.

I am not able to find anything in the theme that does anything to exhibit the above behavior.

Maybe people have encountered something like this before. Is there a fix the above two problems?

https://gohugo.io/content-management/summaries

And some detail about the challenges:
https://github.com/gohugoio/hugo/issues/8910#issuecomment-903158600

1 Like

So, the issue still remains even in the latest versions. Issue being the order of choosing the source for .Summary. The problem is not necessary the order but no way to manually pick the source. Say I want to get the text from summary front matter. Sad thing!

Maybe a new property say .Excerpt (instead of .Summary) could help address the issue by being able to read the front matter value always; just the text.

You can always to something like this to get the front matter summary if it exists:

{{ with .Params.summary }}
  {{ . }}
{{ else }}
  {{ .Summary }}
{{ end }}
1 Like

Oh wow. I think that will address the issue I am facing.

Handling of <!--more--> seems to be a long standing issue. In an ideal case, I would expect for summary front matter to be assume the highest priority followed by <!--more--> followed by autogenerated with summaryLength bound. Because if I provide a summary, I am being explicit about what the excerpt of my post is.

Anyways, thanks a lot for your help.

Regarding the order in which it is chosen, that ship sailed a long time ago, and it is unlikely to change.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.