Skip to content

Add dynamic OG generation #483

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
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Add dynamic OG generation #483

wants to merge 10 commits into from

Conversation

zephraph
Copy link
Collaborator

@zephraph zephraph commented Jun 26, 2025

Adds an /og route that will render an og card for any given page. /og will render the default, /og/getting-started will render for the getting started page, etc. There's a secondary worker that I've added that runs workers-og at og.alchemy.run to render out the actual og image. This theoretically would be a good candidate to get swapped out for a container and just run playwright to snapshot it when needed.

image

@zephraph zephraph requested a review from sam-goodwin June 26, 2025 05:54
Copy link

pkg-pr-new bot commented Jun 26, 2025

Open in StackBlitz

npm i https://pkg.pr.new/sam-goodwin/alchemy@483

commit: bdfe200

@sam-goodwin
Copy link
Owner

Looks like the website deploy failed because SSR is enabled.

Gotta look into why the build doesn't fail when that happens

image

@zephraph zephraph force-pushed the sam/astro-website branch from 9a9b1e8 to 31b1f2e Compare June 26, 2025 23:25
@zephraph zephraph force-pushed the justin/og-image branch 3 times, most recently from ee44edb to 018a1eb Compare June 27, 2025 15:03
@zephraph zephraph force-pushed the sam/astro-website branch from 1591230 to 4ba210c Compare June 27, 2025 20:51
Base automatically changed from sam/astro-website to main July 3, 2025 22:42
Comment on lines 33 to 40
export const ogWorker = await Worker("alchemy-og-worker", {
entrypoint: "./src/og-worker.ts",
routes: [
{
pattern: "og.alchemy.run/*",
},
],
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @sam-goodwin would be good for you to review this specifically

Copy link

github-actions bot commented Jul 4, 2025

🚀 Website Preview Deployed

Your website preview is ready!

Preview URL: https://2a6ae632-alchemy-website.alchemy-run.workers.dev

This preview was built from commit 4643378


🤖 This comment will be updated automatically when you push new commits to this PR.

}

// Base OG image URL
const baseImageUrl = `/og/${route.id ?? "index"}`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here needs to be updated. This shouldn't be /og/ it should be something more like og.alchemy.run/.... I don't exactly know how best to get the domain though. @sam-goodwin this is what I was talking about when mentioning it'd be nice to have a config output that didn't require deployment. It's a bit of a chicken and egg situation because you need the config to be able to deploy but you can only get it by doing the deploy?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a subdomain for og images instead of generating at build time?

@zephraph
Copy link
Collaborator Author

zephraph commented Jul 4, 2025

Okay, here's what's left:

  1. The baseImageUrl in routeData.ts needs to be updated to point at the og worker.
  2. The og worker needs to get the development URL treatment.
  3. Probably should add some cache control headers or manually use the cache API to ensure the og worker isn't generating the og images every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants