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

feat: dynamically create og:image on cloudinary from page title #9

Merged
merged 4 commits into from
Nov 22, 2023

Conversation

joelhooks
Copy link
Collaborator

uses the Head override to create a dynamic og image

Copy link

vercel bot commented Nov 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
course-builder-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 22, 2023 10:29pm
course-builder-poc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 22, 2023 10:29pm

@delucis
Copy link

delucis commented Nov 22, 2023

Heads up that if you like, you can avoid copy/pasting the full Head.astro from the Starlight codebase using the “Reuse a built-in component” pattern:

---
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/Head.astro';

const { data } = Astro.props.entry;
const ogImageUrl = data.ogImageUrl
	? data.ogImageUrl
	: `https://res.cloudinary.com/badass-courses/image/upload/w_1200,h_630,c_fill,f_auto/w_630,h_450,c_fit,co_rgb:FFFFFF,g_west,x_45,y_-40,l_text:arial_60_bold:` +
	  encodeURIComponent(data.title) +
	  `/course-builder-og-image-template_qfarun.png`;
---

<Default {...Astro.props}><slot /></Default>
<meta property="og:image" content={ogImageUrl} />
<meta property="twitter:image" content={ogImageUrl} />

This will render the default <Head> component followed by the two additional <meta> tags.

@joelhooks
Copy link
Collaborator Author

@delucis amazing, thanks! 🎉

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

Successfully merging this pull request may close these issues.

2 participants