Open graph for images in multipage posts

partial/opengraph.html

{{ with .Resources.GetMatch "featured-image.*" }}
  <meta property="og:image" content="{{ .Permalink }}">
{{ else }}
  {{ if and (eq .Params.layout "multipage") (eq .Kind "page") }}
    {{ with .Parent.Resources.GetMatch "featured-image.*" }}
        <meta property="og:image" content="{{ .Permalink }}">
    {{ end }}
  {{ end }}
{{ end }}

I’ve updated the example site we used previously:

git clone --single-branch -b hugo-forum-topic-41042 https://github.com/jmooring/hugo-testing hugo-forum-topic-41042
cd hugo-forum-topic-41042
hugo server
2 Likes