Emit og:image from a cover URL string, not only a media object - #6
Merged
Merged
Conversation
The SEO head only set og:image / twitter:image / JSON-LD image when core
handed it `cover` as a resolved media object ({url, ...}) — which core's
EntryView produces only for a `media`-typed field. A blog that models `cover`
as a `text` field holding an image URL (e.g. danmat.dev, whose covers are
absolute https URLs) got no preview image on any post, even though the theme
rendered the hero from the same string.
BlogHead now accepts either shape: a media object, or a `text` cover holding
an http(s) absolute or site-relative `/path` URL. A `javascript:`/`data:`/
protocol-relative/bare-id value is rejected (no image, plain summary card)
rather than trusted. Removes the now-unused absolute() helper.
Docs: README + agent guide describe cover as media OR a URL string.
Tests: cover as a URL string emits the image across OG/Twitter/JSON-LD;
site-relative is absolutised; unsafe strings yield no image; the media-object
path is unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Flagged by the danmat.dev portfolio agent: blog posts emit no
og:imagefor social/link previews even with a cover set.Root cause (verified on the live site)
BlogHeaddoes mapcover→og:image/twitter:image/ JSON-LDimage— but only when core hands itcoveras a resolved media object{url, ...}. Core'sEntryViewproduces that shape only for amedia-typed field; a field of any other type comes through as a plain string, which the oldis_array()check skipped.danmat's
blog.coveris declaredtextand holds an absolute image URL (e.g.https://danmat.dev/theme/assets/img/plates/aegis-03.jpg). So the theme rendered the hero from that string, but the head contributor received a string and emitted no image — on every post.Fix
BlogHeadnow accepts either shape:{url}(unchanged), or/pathURL.A
javascript:/data:/ protocol-relative//host/ bare-id value is rejected (no image, plain summary card) rather than emitted — same escape-by-default discipline as the canonical handling. The now-unusedabsolute()helper is removed.Docs
README and the agent guide now describe
coveras a media reference or an image URL, and note the ignored-unsafe-value behaviour.Tests
A URL-string cover emits the image across OG/Twitter/JSON-LD; a site-relative cover is absolutised; unsafe strings yield no image; the media-object path is unchanged. phpstan L6 + cs-fixer clean.
Fixes preview images for all existing danmat posts with no content migration — though declaring
coveras amediafield is still the richer model (alt text, dimensions) whenever the site wants to move to it.🤖 Generated with Claude Code