Summaries without images

So I finally updated Hugo… and it seems things have changed. Now when I’m generating list pages and use {{ .Summary | truncate 120 }} on the cards the images appear there, are not filtered out.

Which is a problem - usually each post starts with an image and I don’t want to show it in a summary / truncated content on the cards.

Is there a way to get rid of those images when truncating content?

Here’s what I’d like to achieve:

While currently I have this, when image in the article is present:

Here’s the code I currently have in the section of the template responsible for summary:

        <div class="card-content">
            <div class="content">
                <p class="title is-4"><a class="has-text-black" href="{{ .RelPermalink }}">{{ .Title }}</a></p>
            </div>
            <div class="content">
                {{ .Summary | truncate 120 }}
            </div>
        </div>

for the time being I’ve reverted to 0.131.0 version (extended, deployed via Gitlab CI), but I’d love to hear howto make it work with new one.

The forum’s search function is useful:

https://gohugo.io/functions/transform/plainify

{{ .Summary | plainify | truncate 120 }}

You can define a summary manually, in front matter, or automatically. We changed the rendering of automatic summaries in v0.134.0 (see release notes). Now all three summary types are consistently rendered. Yes, for some sites this was a breaking change, but it had to be done.

1 Like

thank you Jmooring!

@chrillek: actually I did search - but those brought old topics about images. The trick with search is that you need a proper keyword :wink: - it hasn’t occured to me to type “summary includes HTML” in the search box :wink:

2 Likes

“summary” is sufficient. But I agree, it’s not obvious what to look for. I read here regularly, so I had seen these posts some time ago and remembered that something changed with regard to summary.

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