Fix sample page og:image to use stable, hash-free URLs#1251
Open
IEvangelist wants to merge 1 commit into
Open
Conversation
Sample detail pages emitted og:image pointing at the optimized `_astro/<name>.<hash>.webp` thumbnail. Because og:image is an absolute URL against the canonical site (https://aspire.dev), the per-build content hash baked into that path 404s on any deployment whose build hash differs from production's (e.g. staging serves a hash production never built, and vice versa), producing invalid social-card images. Serve each sample's card at a stable, hash-free URL `/og/reference/samples/<sample>.png` via a new prerendered endpoint, mirroring the dynamic `/og/<slug>.png` docs cards. Samples with a primary thumbnail render that thumbnail resized to the canonical 1200x630 social dimensions; samples without one fall back to the same branded card the docs endpoint renders, so every sample resolves to a real PNG. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes broken og:image links on sample detail pages by switching from build-hashed _astro/...<hash>... asset URLs to stable, prerendered PNG URLs under /og/reference/samples/<sample>.png, ensuring social preview images don’t 404 across different deployments/build hashes.
Changes:
- Added a prerendered per-sample OG image endpoint that serves either a resized thumbnail or a branded fallback PNG.
- Updated sample detail pages to always use the stable
/og/reference/samples/<sample>.pngURL forog:image. - Added E2E regression tests ensuring sample pages emit hash-free OG image URLs and that the PNG endpoints resolve.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/frontend/src/pages/og/reference/samples/[sample].png.ts | New prerendered OG image endpoint for stable per-sample social cards. |
| src/frontend/src/pages/reference/samples/[sample]/index.astro | Switches sample pages’ og:image to the stable /og/reference/samples/<sample>.png URL. |
| src/frontend/tests/e2e/og-metadata.spec.ts | Adds E2E coverage for stable sample OG metadata and resolvable PNG endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Problem
Sample detail pages emitted
og:imagepointing at the optimized_astro/<name>.<contentHash>.webpthumbnail. Becauseog:imageis an absolute URL against the canonical site (https://aspire.dev), the per-build content hash baked into that path 404s on any deployment whose build hash differs from production's — e.g. staging serves a hash production never built (and vice versa). Result: invalid social-card images on the new samples pages.Reported on staging:
https://aspiredev-klciommkyhpvc-vnext-release.azurewebsites.net/reference/samples/node-express-redis/— theog:imageresolved tohttps://aspire.dev/_astro/node-express-redis-primary-page-light.<hash>.webp, whichaspire.devnever served.Fix
Serve each sample's social card at a stable, hash-free URL
/og/reference/samples/<sample>.pngvia a new prerendered endpoint, mirroring the existing dynamic/og/<slug>.pngdocs cards.page-metadata.tsdeclares inog:image:width/og:image:height.renderOgImagePng), so every sample resolves to a real PNG instead of 404ing.The detail page now points
og:imageat this endpoint for all samples.Changes
src/pages/og/reference/samples/[sample].png.ts— prerendered per-sample OG endpoint (thumbnail or branded-card fallback), immutable cache headers.src/pages/reference/samples/[sample]/index.astro—og:imagenow references the stable endpoint URL instead of the hashed_astroasset.tests/e2e/og-metadata.spec.ts— regression coverage asserting sample pages emit a stable, hash-freeog:image(no_astro), 1200x630 dims, matchingtwitter:image, and that the PNG resolves — for both a thumbnail sample (node-express-redis) and a thumbnail-less one (aspire-with-node).Verification
pnpm lintpassed.dist/og/reference/samples/.og:image=https://aspire.dev/og/reference/samples/<sample>.pngwith no_astroreferences; dims 1200x630;twitter:imagematches.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com