Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGraph image width and height tags missing in _internal/opengraph.html template #13478

Open
dansailer opened this issue Mar 7, 2025 · 1 comment

Comments

@dansailer
Copy link

Meta documentation of open graph suggests to always use the og:image:width and og:image:height tags.

Use og:image:width and og:image:height Open Graph tags:
Using these tags will specify the image dimensions to the crawler
so that it can render the image immediately without having to asynchronously
download and process it.

Is there a reason, why they are missing in tpl/tplimpl/embedded/templates/opengraph.html?

Something a long those lines, would solve the missing card previews in WhatsApp, etc.

{{- with partial "_funcs/get-page-images" . }}
  {{- range . | first 6 }}
    <meta property="og:image" content="{{ .Permalink }}">
    {{ with $.Page.Resources.Get .Image }}
      <meta property="og:image:width" content="{{ .Width }}">
      <meta property="og:image:height" content="{{ .Height }}">
    {{ end }}
  {{- end }}
{{- end }}
@jmooring
Copy link
Member

jmooring commented Mar 7, 2025

Is there a reason, why they are missing in tpl/tplimpl/embedded/templates/opengraph.html?

Not sure... a desire for consistent output perhaps?

The _funcs/get-page-images partial returns a permalink regardless of whether an image is a resource. For example, a permalink may be for an image in the static directory, or a remote image. Unless it's a resource, we don't have access to dimensions. Even if the image is a resource, it may have a media type that we can't decode (e.g., image/avif, image/svg+xml, etc.).

I don't see anything wrong with conditionally including width and height meta elements, but I'd change the partial to return width, height, and media type (if available) along with the permalink and relpermalink. I'm not sure why it optionally includes the resource itself, but I guess there's no harm in keeping it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants