Strip images from Summary

Hello there,

I would like to get the Summary of a post without the picture contained in it.


The posts I publish usually start with a picture. Unfortunately this picture also appears in the description on Google search results.

For example, if a post starts with an image like this:

![Linux install bat](/illustrations/linux-bat-installation-on-debian-10.en/linux-bat-installation-on-debian-10.en.png)

The description in Google will look like:

27 mai 2021 — Linux: install bat. bat is a command-line tool to display text files and provides syntax highlighting, git integration and …

(to be clear, I would like to hide the part “Linux install bat.”)

Is there something like this

 <meta name="description" content="{{ .Summary | stripImages }}">

in Hugo?

On the page in question, how is this rendered?

<meta name="description" content="{{ .Summary }}">

Hi @jmooring, and thank you for considering my request.

Using .Summary unfortunately breaks the build, and I don’t understand why

I’ve found a related topic on this forum but I’m not familiar with “the scope, the context and the dot”, any hint would be warmly welcome!

This is an important concept. Take some time to understand it.

Replace this:

{{- with ($.Scratch.Get "Description") }}
  <meta name="description" content="{{ .Summary }}">
{{- end }}

With this:

<meta name="description" content="{{ .Summary }}">

The build is repaired, and images are not showing up anymore in the description, thanks a lot @jmooring !

This is an important concept. Take some time to understand it.

I will, definitively, thanks for the advice

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