-
Notifications
You must be signed in to change notification settings - Fork 95
Add build-time Open Graph image generation for documentation pages #484
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
The /api/og route cannot work with output: 'export' which is used by this project. Next.js API routes are not supported in static exports. Removed the API route to fix the build failure. Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Fixed in commit 86bd0d8. The build was failing because this repository uses I've removed the
To implement dynamic OG images, the project would need to either:
The build should now pass. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Properly revert page.tsx to use doc.image instead of the non-existent /api/og route Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
|
@copilot non, l'idee serait de generer le thumnail au build ! (tout comme les pages) |
Add prebuild script that generates static OG images for all documentation pages using @vercel/og. Images are created at build time and saved to public/og/, making them compatible with static export.
- Created scripts/generate-og-images.mts to crawl MDX files and generate 1200x630 PNG images
- Updated package.json to add @vercel/og and tsx dependencies
- Added prebuild script to run OG generation before Next.js build
- Updated page metadata to reference generated images at /og/{slug}.png
- Added public/og/ to .gitignore as build artifacts
This approach works with output: 'export' by generating images at build time rather than runtime.
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Exactement ! Implemented in commit 89c4485. The OG images are now generated at build time using a prebuild script:
Each page now gets a branded thumbnail with the site name, page title, description, and theme colors. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot cool, peux-tu inclure les thumbnails generes afin qu'ils apparaissent dans Chromatic (afin qu'ils soient eux aussi: visual testés) |
Remove public/og/ from .gitignore and commit the generated OG images so they are tracked in the repository and included in Chromatic visual regression tests. Generated images: - getting-started/authoring.png - getting-started/github-actions.png - getting-started/introduction.png Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Done in commit 55774e8. The generated OG images are now committed to the repository in Committed images:
The images will be regenerated on each build and can be visually tested in Chromatic for any changes. |
i want them to be part of the build but not git-tracked (as they are generated) |
… navigation Changed Playwright tests to use page.setContent() with <img> tags instead of navigating directly to PNG files. This ensures: - Images render properly in an HTML context - Chromatic captures the actual image content, not a broken file - Tests work consistently across different static file servers Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
... Fixed in commit 5ecbfa9. You were absolutely right! Navigating directly to the PNG file was causing the issue. Changed the tests to use await page.setContent(`
<!DOCTYPE html>
<html>
<body style="margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #000;">
<img src="/og/getting-started/introduction.png" alt="Introduction OG Image" style="max-width: 100%; height: auto;" />
</body>
</html>
`)This ensures the images render properly in an HTML context and Chromatic can capture the actual image content instead of a broken file. |
abernier
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scripts/copy-og-images.mts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ce script n'est maintenant je pense plus necessaire, tu peux l'enlever lui et ses references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit e5cd050. Removed the copy-og-images script - you're right that it's not needed since Next.js build automatically copies files from public/ to out/ during static export.
scripts/README.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ne documente pas : c'est trivial
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit e5cd050. Removed scripts/README.md.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setContent: reutilise un meme template entre les 3?
nb: simplifie au max, pas besoin de title... etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit e5cd050. Created shared ogImageTemplate() function and simplified HTML to bare minimum - just body with styles and img tag.
- Removed scripts/copy-og-images.mts (no longer needed - Next.js build copies public/ to out/) - Removed scripts/README.md (documentation was trivial) - Simplified OG image tests to use shared template function - Removed unnecessary HTML elements (doctype, html, head, title, alt attributes) - Made test code more DRY and maintainable Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
abernier
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package-lock.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot supprime on est sur pnpm !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit d07ba60.
src/app/[...slug]/page.test.ts
Outdated
| // | ||
|
|
||
| const ogImageTemplate = (src: string) => ` | ||
| <body style="margin:0;display:flex;justify-content:center;align-items:center;min-height:100vh;background:#000"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pas la peine de changer le margin, display, background du body ou meme sa taille... fais au plus simple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit d07ba60. Simplified to just <body><img src="${src}" /></body>.
- Deleted package-lock.json (repo uses pnpm, not npm) - Simplified ogImageTemplate to bare minimum (just body and img tags) - Removed unnecessary inline styles (margin, display, justify-content, align-items, min-height, background, max-width, height) Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
|
@copilot les test() pour les images og n'ont eux (contrairement aux autres pour les pages responsives) pas besoin de se faire dans plusieurs formats de viewport (actuellement définis globalement dans la playwright.config.ts) comment eviter les snapshots responsives pour ces tests d'images og uniquement ? |
Wrapped OG image tests in test.describe() block and added test.skip() to skip the w375 viewport project. OG images are always 1200x630 pixels so they don't need to be tested at multiple viewport sizes like the responsive page tests. Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Fixed in commit 96705a8. Wrapped the OG image tests in a |
|
@copilot ci fails since your last commit |
The test.skip() was using an unused browserName parameter from the fixtures destructuring, which caused a CI failure. Fixed by removing the unused parameter. Co-authored-by: abernier <76580+abernier@users.noreply.github.com>




Build-time OG Image Generation
Implementation
Created a build-time script that generates Open Graph images before the Next.js build:
Features:
public/og/{slug}.pngScript:
scripts/generate-og-images.mtsBuild Process: Integrated into build script
tsx scripts/generate-og-images.mts && next buildpublic/files toout/during static exportPage Metadata: Updated
[...slug]/page.tsx/og/${slug.join('/')}.pngChromatic Tests:
[...slug]/page.test.tsintroduction og)ogImageTemplate()functionExample Output
The generated images feature:
Why External Script (Not opengraph-image.tsx)
Next.js Limitation:
opengraph-image.tsxcannot be used inside catch-all routes like[...slug]. Attempting to use it results in a build error:While
opengraph-image.tsxworks for static routes and simple dynamic routes, it's incompatible with catch-all segments. The external script approach is the only solution that works with both:output: 'export')[...slug])Build Artifacts & Chromatic
The generated OG images are not committed to the repository as they are build artifacts:
public/og/is in.gitignoreHowever, the images are captured by Chromatic for visual testing:
pnpm run buildinstart.sh)public/og/toout/og/Technical Details
buildscriptoutput: 'export')This approach fulfills the requirement for dynamic per-page thumbnails while remaining compatible with the repository's static export configuration and ensuring comprehensive visual regression testing.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.