From 9bb6f3066c1ed27ebfff8402cc93c2d1c2dce1d0 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Mon, 9 Sep 2024 10:30:53 +0200 Subject: [PATCH] feat(seo): include default SEO image url in OpenGraph image --- src/utils/seo.ts | 5 ++++- studio/lib/queries/companyInfo.ts | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils/seo.ts b/src/utils/seo.ts index 002d46694..7a2fb2113 100644 --- a/src/utils/seo.ts +++ b/src/utils/seo.ts @@ -26,6 +26,7 @@ type CompanyInfo = { brandAssets: { favicon: string; }; + defaultSEO: SeoData; }; export async function fetchSeoData( @@ -95,12 +96,14 @@ export async function generateMetadataFromSeo( title: title, ...(description ? { description: description } : {}), })}`; + const imageUrl = + seo?.imageUrl || companyInfo?.defaultSEO?.imageUrl || fallbackImageUrl; return { title: title, description: description, openGraph: { - images: [seo?.imageUrl ?? fallbackImageUrl], + images: [imageUrl], }, icons: { icon: icons }, keywords: keywords, diff --git a/studio/lib/queries/companyInfo.ts b/studio/lib/queries/companyInfo.ts index 75f8d3b25..54452eab9 100644 --- a/studio/lib/queries/companyInfo.ts +++ b/studio/lib/queries/companyInfo.ts @@ -3,5 +3,11 @@ import { groq } from "next-sanity"; export const COMPANY_INFO_QUERY = groq`*[_type == "companyInfo"]{ brandAssets, siteMetadata, + defaultSEO { + "title": seoTitle, + "description": seoDescription, + "keywords": seoKeywords, + "imageUrl": seoImage.asset->url + }, legalPages, }[0]`;