Repository navigation
Add OG image and social preview meta tags #2233
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
Open
astra-intelligence
wants to merge
4
commits into
git:gh-pages
Choose a base branch
from
astra-intelligence:add-og-social-preview
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+128
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e92161
Add OG image and social preview meta tags
astra-intelligence 2bd970a
Address review: og:image is now a real site screenshot via Playwright…
astra-intelligence 57b356a
Fix take-og-image.js server-ready wait: drop redundant stderr handler…
astra-intelligence 2a9b903
Address review: compose OG card to exclude release box and avoid bott…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #!/usr/bin/env node | ||
| // @ts-check | ||
|
|
||
| /** | ||
| * Generate a 1200x630 Open Graph image for git-scm.com by taking a real | ||
| * screenshot of the built site, so the card reflects the site's actual look | ||
| * and feel. | ||
| * | ||
| * Usage: | ||
| * node script/take-og-image.js [worktree-path] | ||
| * | ||
| * The optional WORKTREE-PATH points at a git-scm.com worktree (default: the | ||
| * current directory). The script builds the site with Hugo, serves the built | ||
| * site with script/serve-public.js, captures the homepage in light mode at a | ||
| * 1200x630 clip, and writes the result to static/images/og-image.png in that | ||
| * worktree. | ||
| * | ||
| * This mirrors the repo's existing screenshot tooling | ||
| * (script/compare-screenshots.js) — same build/serve helpers, same Playwright | ||
| * stack — so the OG image is a genuine snapshot of the site rather than a | ||
| * hand-drawn card that would look nothing like git-scm.com. | ||
| */ | ||
|
|
||
| const { chromium } = require('@playwright/test'); | ||
| const { spawn, execSync } = require('child_process'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const WORKTREE = path.resolve(process.argv[2] || '.'); | ||
| const PORT = 5100; | ||
| const VIEWPORT = { width: 1280, height: 720 }; | ||
| // 1200x630 social card: header + hero + the first two rows of the feature | ||
| // grid. The homepage's bottom half (release box and lower cards) is hidden so | ||
| // the card never shows a stale release version and nothing is cut off at the | ||
| // bottom edge. | ||
| const CLIP = { x: 40, y: 0, width: 1200, height: 630 }; | ||
| const OUTPUT = path.join(WORKTREE, 'static', 'images', 'og-image.png'); | ||
|
|
||
| /** | ||
| * Compose the screenshot region: hide the ever-changing release box (which | ||
| * hard-codes the latest version number) plus lower-page content so the clip | ||
| * reads as a complete, timeless view of the site. | ||
| */ | ||
| async function composeForScreenshot(page) { | ||
| await page.evaluate(() => { | ||
| const hide = (sel) => document.querySelectorAll(sel).forEach((el) => { el.style.display = 'none'; }); | ||
| hide('#front-downloads'); // "Latest source release" box with version number | ||
| hide('#front-book'); // Pro Git promo row below the feature grid | ||
| // Keep only the first two feature-grid rows so the 1200x630 clip ends on a | ||
| // clean boundary instead of slicing the "Install"/"Community" row. | ||
| const lis = document.querySelectorAll('#front-nav ul li'); | ||
| for (let i = 4; i < lis.length; i++) lis[i].style.display = 'none'; | ||
| const ul = document.querySelector('#front-nav ul'); | ||
| if (ul) ul.style.paddingBottom = '24px'; | ||
| }); | ||
| } | ||
|
|
||
| async function startServer() { | ||
| console.error(`Building Hugo site in ${WORKTREE}...`); | ||
| execSync('hugo', { cwd: WORKTREE, stdio: 'inherit' }); | ||
|
|
||
| const serverScript = path.join(WORKTREE, 'script', 'serve-public.js'); | ||
| const server = spawn('node', [serverScript], { | ||
| cwd: WORKTREE, | ||
| env: { ...process.env, PORT: String(PORT) }, | ||
| stdio: ['ignore', 'pipe', 'inherit'], | ||
| }); | ||
|
|
||
| await new Promise((resolve, reject) => { | ||
| const timeout = setTimeout(() => reject(new Error('Server startup timeout')), 30000); | ||
| server.stdout.on('data', (data) => { | ||
| if (data.toString().includes('Now listening')) { | ||
| clearTimeout(timeout); | ||
| resolve(); | ||
| } | ||
| }); | ||
| server.on('error', (err) => { | ||
| clearTimeout(timeout); | ||
| reject(err); | ||
| }); | ||
| }); | ||
|
|
||
| return server; | ||
| } | ||
|
|
||
| async function main() { | ||
| const server = await startServer(); | ||
| const browser = await chromium.launch(); | ||
|
|
||
| try { | ||
| const context = await browser.newContext({ | ||
| viewport: VIEWPORT, | ||
| colorScheme: 'light', | ||
| }); | ||
| const page = await context.newPage(); | ||
|
|
||
| console.error(`Navigating to: http://localhost:${PORT}/`); | ||
| await page.goto(`http://localhost:${PORT}/`, { waitUntil: 'networkidle' }); | ||
|
|
||
| await composeForScreenshot(page); | ||
|
|
||
| fs.mkdirSync(path.dirname(OUTPUT), { recursive: true }); | ||
| await page.screenshot({ path: OUTPUT, clip: CLIP }); | ||
| console.error(`Saved: ${OUTPUT} (${CLIP.width}x${CLIP.height} clip of the homepage)`); | ||
| } finally { | ||
| await browser.close(); | ||
| server.kill(); | ||
| } | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
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.
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.
Hmm. This screenshot feels like it was taken last millenium... Maybe we could have a more current one?
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.
The new image looks better, but it 1) is cut off at the bottom, and 2) contains the hard-coded version v2.56.0 (which won't age well)...
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.
Two concerns, and a suggestion: 1) now the part where the version was looks a bit empty, oddly so, and 2) it looks as if the PR branch was never rewritten, so that the faulty commits stay there forever, whereas I really like the PR branches to be rewritten before merging (but then, I am not the only person merging here, so you might find someone else willing to merge in the current form). Suggestion: how about pulling the version back in, but updating the
og-image.pngas part of the script that updateshugo.ymlwhenever a new Git version comes out, as a separate commit?Also, I wonder whether OpenGraph has anything for dark mode?