Truncated Post Help

I am trying to work on a custom theme, and I wanted to do truncated posts on the main feed. I followed the instructions from this post. Truncated posts on your microblog, but it doesn’t seem to be working. I thought maybe another set of eyes would see what maybe I missed. My other thought would be I’m on Hugo .91; maybe this broke something that used to work? I don’t know. Any help would be great!

{{ define "main" }}
<div class="home h-feed">
  <ul class="post-list">
  {{ $paginator := .Paginate (where .Pages.ByDate.Reverse "Type" "post") (index .Site.Params "archive-paginate" | default 25) }}
  {{ range $paginator.Pages  }}
      <li class="h-entry">
    {{ if .Title }}
      <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
    {{ end }}
        <a href="{{ .Permalink }}" class="u-url"><span class="post-meta"><time class="dt-published" datetime="{{ .Date.Format "2006-01-02 15:04:05 -0700" }}">{{ .Date.Format "Jan 2, 2006" }}</time></span></a>
        <div class="e-content">
          {{ .Summary }}
          {{ if .Truncated }}
            <p><a href="{{ .RelPermalink }}">Read More</a></p>
          {{ end }}
    {{ end }}
  <p class="rss-subscribe">subscribe <a href="{{ "feed.xml" | absURL }}">via RSS</a></p>
{{ end }}

I can’t see anything wrong with that template. But, you probably want to add support for truncated posts in more templates. For example, the homepage uses the template file layouts/index.html.

Thanks, adding it to layouts/index.html fixed it for me.

I’ve noticed photos get truncated when posted if I do a small blurb of text I have to click into the post to actually see the photo. I wonder if there is a way to fix this?

That has to do with {{ .Summary }} stripping away images. For more details, read my answer in the other thread.

For the photos issue, I wonder if you could check to see if .Content contains “img”, and if so show it, otherwise use .Summary. This wouldn’t work well for long photo posts, though.

1 Like