Skip to content

Commit

Permalink
feat(openGraph): ensure 1200x630 with transparent fill
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Sep 10, 2024
1 parent bd1df00 commit 3dc95c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/utils/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ export async function generateMetadataFromSeo(
): Promise<Metadata> {
const companyInfo = await fetchCompanyInfo();

const title = seo?.title || companyInfo?.siteMetadata?.siteName || "Variant";
const description = seo?.description;
const title =
seo?.title ||
companyInfo?.defaultSEO?.title ||
companyInfo?.siteMetadata?.siteName ||
"Variant";
const description = seo?.description || companyInfo?.defaultSEO?.description;
const keywords = seo?.keywords || "";

const favicon = companyInfo?.brandAssets?.favicon;
Expand All @@ -96,8 +100,17 @@ export async function generateMetadataFromSeo(
title: title,
...(description ? { description: description } : {}),
})}`;
const imageUrl =
seo?.imageUrl || companyInfo?.defaultSEO?.imageUrl || fallbackImageUrl;
const sanityImageUrl = seo?.imageUrl || companyInfo?.defaultSEO?.imageUrl;
const sanityImageParams = `?${new URLSearchParams({
w: "1200",
h: "630",
fit: "fill",
fm: "png", // required for transparent
bg: "00000000", // transparent
})}`;
const imageUrl = sanityImageUrl
? `${sanityImageUrl}${sanityImageParams}`
: fallbackImageUrl;

return {
title: title,
Expand Down
3 changes: 3 additions & 0 deletions studio/schemas/objects/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const seo = defineField({
name: seoFieldID.image,
title: "Social Media Image",
type: "image",
options: {
hotspot: true,
},
description:
"A compelling image for social media can greatly improve conversion rates, even though it doesn't directly affect SEO.",
}),
Expand Down

0 comments on commit 3dc95c2

Please sign in to comment.