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

v3 - add missing SEO data #850

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions src/app/(main)/[lang]/[...path]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,22 @@ 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";

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<ReturnType<typeof fetchPageDataFromParams>>,
): SeoData | null {
Expand All @@ -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;
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/utils/seo.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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(","),
};
}