Hugo summaryLength Doesn't Work?

Dear All

I added {{ .Summary }} on my list.html like this →

{{ partial "head.html" . }}
{{ partial "header.html" . }}

<main class="main">

<header class="post-entry">
<a href="{{ .Permalink }}">
<h1>{{ .Title }}</h1>
</a>
</header>

{{ range (.Paginate (.Pages).Reverse).Pages }}
<article class="post-entry">
<a href="{{ .Permalink }}">
<header class="entry-header">
<h2>{{ .Title }}</h2>
</header>
<section class="entry-content">
{{ if eq .Section "quote" }}
<blockquote>
<h3>
{{ .Summary }}
{{ if .Truncated }} ... {{ end }}
</h3>
</blockquote>
{{ else }}
<h3>
{{ .Summary }}
{{ if .Truncated }} ... {{ end }}
</h3>
<div class="read-more">➜</div>
{{ end }}
</section>
</a>
</article>
{{ end }}

<nav class="pagination">
<a class="prev" href="{{ if .Paginator.HasPrev }}{{ .Paginator.Prev.URL }}{{ else }}#{{ end }}">« Prev</a>
<a class="next" href="{{ if .Paginator.HasNext }}{{ .Paginator.Next.URL }}{{ else }}#{{ end }}">Next »</a>
</nav>

</main>

{{ partial "footer.html" . }}

Also I added summaryLength: 30 on my config.yaml like this →

baseURL: https://angora.me

title: Bayu Angora

paginate: 6
paginatePath: /
summaryLength: 30

permalinks:
  blog: /:title/
  poem: /:title/
  quote: /:title/

The paginate: 6 and paginatePath: / is work without any issue. But the summaryLength: 30 is doesn’t work and display randomly. Sometime less than 30, sometimes more than 40 like this → Blog | Bayu Angora

How to fix this summaryLength?

Regards

Hi!

I did not look into Hugo’s source code, but I think summaryLength respects a combination of the number of words and paragraphs.

If summaryLength does not fit you could use something like

{{ .Content | safeHTML | truncate 300 }}

I really like your website layout!

1 Like

Thanks, @Grob. Now I use {{ .Summary | truncate 120 }} and it works. I just curious, if summaryLength still respecting combination of words and paragraph, then it only works for truncating article with long first paragraph, right?

Yes, that’s the current behaviour.

This ‘article’ won’t be truncated at all:


asdf asdf asdf asdf

asdf asdf asdf asdf

asdf asdf asdf asdf

asdf asdf asdf asdf

asdf asdf asdf asdf

asdf asdf asdf asdf

asdf asdf asdf asdf

asdf asdf asdf asdf

asdf asdf asdf asdf

asdf asdf asdf asdf

asdf asdf asdf asdf

I am not quite whether this really is the intended default behaviour.