Skip to content
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

opengraph images #370

Merged
merged 5 commits into from
Feb 17, 2025
Merged

opengraph images #370

merged 5 commits into from
Feb 17, 2025

Conversation

deansallinen
Copy link
Contributor

This PR:

  • add support for multiple layouts
  • include token-based authentication for image generator service
  • add test page for opengraph images at /debug/opengraph
  • add basic index page for the various debug pages

The opengraph image needs to be accessible from a url like http://unicove.com/en/eos/og_default.png in the head of the document, but we also need some way of changing the image parameters e.g. title, text, layout, language, etc.

There were two approaches I considered to include all the various options we needed for generation:

  1. add them to the image url like http://unicove.com/en/eos/layout-1/Title%20of%20the%20image/Text%20of%20image/og_default.png or http://unicove.com/en/eos/og_default.png?text=Text%20of%20image&layout=1

Upside to this approach is all configuration could happen at the +page.ts load function of the particular route.

But using params like this would open the api to potential abuse and create massive urls. Even with a token-based authentication between unicove.com and the image-generator service, anyone could just change the query params and unicove would generate a valid image

  1. map image routes to their image generator properties

example: http://unicove.com/en/eos/send uses the image at http://unicove.com/en/eos/api/og/send.png which uses the predefined options for that route (text, title, layout, language, network, etc.)

The upside is no invalid images can be generated, but the tradeoff is all configuration needs to be done in a centralized place (in this case, the object at the api endpoint)

Note: two new env variables are needed

API_OPENGRAPH_GENERATOR is the url of the endpoint for the image generator
API_OPENGRAPH_TOKEN is the shared token that matches the endpoint

Copy link

cloudflare-workers-and-pages bot commented Feb 14, 2025

Deploying 2nicove with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1868fb9
Status: ✅  Deploy successful!
Preview URL: https://88d67c15.unicove2.pages.dev
Branch Preview URL: https://og-auth-headers.unicove2.pages.dev

View logs

@aaroncox aaroncox merged commit cd337b3 into dev Feb 17, 2025
2 checks passed
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