Fix sample page og:image to use stable, hash-free URLs#1251
Conversation
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.
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>
d73ee64 to
f0b856d
Compare
Frontend HTML artifact readyThe latest frontend build uploaded the This comment updates automatically when a new frontend build artifact is uploaded. |
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