Detection how .Summary was built?

  • In a file layouts/_default/list.html I want to link hugo articles in a loop { range .Pages }}...{{ end }}.
  • Additionally I want to output a text. In this hierarchy:
{{- with (.Summary | default .Params.summary | default .Description) -}}
<p class="card-text">{{ . }}</p>
{{- end -}}

(!!)but it should never be the automatic .Summary(!!).


If there is a .Summary because there is a <!--more--> in the content, output that.
If not:
the .Params.summary or the .Description.

For a test I have

  • removed the front-matter summary and <!--more--> in a content file.
  • set summaryLength in the configuration to 0. Unfortunately, this results in an automatic summary up to the first period in the content and not an empty one. By the way, even if I set summaryLength to -1, 1 or similarly small the summary is the same.

The check for .isTruncated does not distinguish between an automatic summary and a summary because of <!--more-->. Both are true.

Question: Is there any way to detect whether a summary was created automatically or because of a <!--more-->?

Related docs: Content Summaries | Hugo

Try this

{{- $Summary := .Summary -}}

{{- /* 
  Assign $Summary with .Description, if these conditions are met
  1. `.RawContent` doesnt contains `<!--more-->`
  2. `.Params.summary` is unset or falsy value
*/ -}}
{{- if and (not (strings.Contains .RawContent "<!--more-->")) (not .Params.summary) -}}
  {{- $Summary = .Description -}}
{{- end -}}

{{- with $Summary -}}
  <p class="card-text">{{ . }}</p>
{{- end -}}
1 Like

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