No Code to Truncate Posts on Home Page

I’d like to truncate longer posts on my home page. According to https://help.micro.blog/t/truncated-posts-on-your-microblog/60, there should be a custom theme template I can edit called list.html that contains the following code:

<div class="e-content">
    {{ .Content }}
  </div>

However, the only template I can find called list.html appears under Templates for Arabica theme and is called layouts/_default/list.html. This template does not contain the code shown above. Its contents are:

{{ define "body_class" }}tag-template{{ end }}
{{ define "title" }}{{ .Title }}{{ end }}
{{ define "main" }}
{{ $paginator := .Paginate (where .Pages.ByDate.Reverse "Type" "post") (index .Site.Params "archive-paginate" | default 25) }}
<main class="content" role="main">
  {{ if not $paginator.HasPrev }}
    {{ if eq .Data.Plural "tags" }}
      <h2 class="tag-title">{{ .Title }}</h2>
    {{ end }}
  {{ end }}

	<div class="extra-pagination">
	    {{ partial "pagination.html" .}}
	</div>
  {{ range $paginator.Pages  }}
  {{ .Render "summary"  }}
  {{ end  }}
  {{ partial "pagination.html" .  }}
</main>
{{ end }}

The templates listed under Default Templates do not include any called list.html.

I’m at a loss, therefore, as to how to truncate longer posts by default, and would appreciate any help you can offer.

When you say, “on my homepage” that means you need to look for layouts/index.html not the list template. You probably will find {{ .Content }} there and you can replace that with {{ .Summary }} or a custom truncate format.

1 Like

Thanks for your help :slight_smile:

I don’t know what to do with the template layouts/index.html - it contains the following:

{{ define "main" }}
	<main class="content" role="main">
    {{ $paginator := .Paginate (where .Site.Pages "Type" "post") }}
    <div class="extra-pagination">
      {{ partial "pagination.html" . }}
    </div>
		{{ range $paginator.Pages }}
      {{ .Render "summary" }}
		{{ end }}
    {{ partial "pagination.html" . }}
	</main>
{{ end }}

Would {{ .Summary }} work somewhere in there?

Render summary should already be providing a truncated post. Unless your theme has a specific summary.html template that overrides the defaults. By default, Hugo summaries are the first 70 words of your post.

Hmm. It’s not truncating the posts, though. I’ll write to Help, though I’m sure @Manton is busy already on this last day of the year. Thanks again, @jsonbecker :slight_smile: