Use where with If Is.Page

Context
We are trying to streamline content production. Our current process involves creating an image in Figma, adding to Cloudinary, and then adding it to the post’s frontmatter.

We want to automate this process. I believe I am nearly there (I think). I have a base image within /assets that I overlay with text. This works.

The problem is Hugo is generating an image for almost every page.

  • It does not generate an image for pages that point to a local image within the frontmatter.
  • It does generate an image for pages that don’t point image - expected behavior.
  • It does generate an image for pages that point to a cloudinary URL - not expected behavior.

Is it possible to add a where function to If .IsPage? Code below:

{{- if .IsPage -}}
  {{ $base := resources.Get "og_base.png" }}
  {{ $boldFont := resources.Get "/InstrumentSans-SemiBold.ttf" }}
  {{ $img := $base.Filter (images.Text .Page.Title (dict
    "color" "#ffffff"
    "size" 52
    "linespacing" 2
    "x" 70
    "y" 450
    "font" $boldFont
  ))}}

  {{ $img = resources.Copy (path.Join .Page.RelPermalink "og.png") $img }}
  <meta property="og:image" content="{{$img.Permalink}}">
  <meta property="og:image:width" content="{{$img.Width}}" />
  <meta property="og:image:height" content="{{$img.Height}}" />

(As you can probably guess, I am not a developer.) Any help is appreciated.

Link to code

I’ve read your post a few times, and I don’t understand what you’re asking for.

Is it possible to stop Hugo generating og images for posts where the OG image is already pointing to Cloudinary?

How would we know that?

There’s a possibility this isn’t possible.

I was attempting chain a filter Is.Page, so:

If Is.Page and (that page’s params.image does not include ‘https://cloudinary’)…

If I understand properly, maybe something like:

{{ if and .IsPage (not (findRE `^https://cloudinary` .Params.image)) }}
  ...
{{ end }}