From db51c356c0e38ae518d6cfeafa11ca2720a57717 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Thu, 31 Oct 2024 15:43:02 +0100 Subject: [PATCH] feat: add missing SEO data for customer cases and dynamic pages --- src/app/(main)/[lang]/[...path]/page.tsx | 36 ++++++++---------------- src/utils/seo.ts | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/app/(main)/[lang]/[...path]/page.tsx b/src/app/(main)/[lang]/[...path]/page.tsx index cfacc58e8..1a4e150eb 100644 --- a/src/app/(main)/[lang]/[...path]/page.tsx +++ b/src/app/(main)/[lang]/[...path]/page.tsx @@ -12,11 +12,15 @@ import Legal from "src/components/legal/Legal"; import LegalPreview from "src/components/legal/LegalPreview"; import PageHeader from "src/components/navigation/header/PageHeader"; import { homeLink } from "src/components/utils/linkTypes"; -import { ChewbaccaEmployee } from "src/types/employees"; import { getDraftModeInfo } from "src/utils/draftmode"; import { fetchPageDataFromParams } from "src/utils/pageData"; import SectionRenderer from "src/utils/renderSection"; -import { SeoData, generateMetadataFromSeo } from "src/utils/seo"; +import { + SeoData, + generateMetadataFromSeo, + seoDataFromChewbaccaEmployee, + seoDataFromCustomerCase, +} from "src/utils/seo"; export const dynamic = "force-dynamic"; @@ -24,17 +28,6 @@ type Props = { params: { lang: string; path: string[] }; }; -function seoDataFromChewbaccaEmployee(employee: ChewbaccaEmployee) { - return { - title: employee.name ?? undefined, - description: employee.email ?? undefined, - imageUrl: employee.imageThumbUrl ?? undefined, - keywords: [employee.name, employee.email, employee.telephone] - .filter((d) => d != null) - .join(","), - }; -} - function seoDataFromPageData( data: Awaited>, ): SeoData | null { @@ -43,22 +36,17 @@ function seoDataFromPageData( } switch (data.docType) { case "customerCase": - // TODO - return null; + return seoDataFromCustomerCase(data.queryResponse.customerCase.data); case "customerCasesPage": return data.queryResponse.data.seo; case "pageBuilder": - // TODO - return null; - case "legalDocument": - // TODO - return null; - case "compensations": { + return data.queryResponse.data.seo; + case "compensations": return data.queryResponse.compensationsPage.data.seo; - } - case "employee": { + case "employee": return seoDataFromChewbaccaEmployee(data.queryResponse); - } + case "legalDocument": + return null; } } diff --git a/src/utils/seo.ts b/src/utils/seo.ts index 5fd4b3acd..577aed0df 100644 --- a/src/utils/seo.ts +++ b/src/utils/seo.ts @@ -1,5 +1,7 @@ +import imageUrlBuilder from "@sanity/image-url"; import { Metadata } from "next"; +import { ChewbaccaEmployee } from "src/types/employees"; import { urlFor } from "studio/lib/image"; import { BrandAssets } from "studio/lib/interfaces/brandAssets"; import { CompanyInfo } from "studio/lib/interfaces/companyDetails"; @@ -10,6 +12,8 @@ import { DEFAULT_SEO_QUERY, } from "studio/lib/queries/siteSettings"; import { loadStudioQuery } from "studio/lib/store"; +import { sharedClient } from "studioShared/lib/client"; +import { CustomerCase as CustomerCaseDocument } from "studioShared/lib/interfaces/customerCases"; export type SeoData = { title?: string; @@ -79,3 +83,28 @@ export async function generateMetadataFromSeo( keywords: keywords, }; } + +export function seoDataFromChewbaccaEmployee(employee: ChewbaccaEmployee) { + return { + title: employee.name ?? undefined, + description: employee.email ?? undefined, + imageUrl: employee.imageThumbUrl ?? undefined, + keywords: [employee.name, employee.email, employee.telephone] + .filter((d) => d != null) + .join(","), + }; +} + +export function seoDataFromCustomerCase(customerCase: CustomerCaseDocument) { + return { + title: customerCase.basicTitle, + description: customerCase.description, + imageUrl: imageUrlBuilder(sharedClient).image(customerCase.image).url(), + keywords: [ + customerCase.projectInfo.name, + customerCase.projectInfo.customer, + customerCase.projectInfo.sector, + ...customerCase.projectInfo.deliveries.map((d) => d.delivery), + ].join(","), + }; +}