Skip to content

Commit

Permalink
Standardize generateMetadata on entities
Browse files Browse the repository at this point in the history
  • Loading branch information
bookernath committed Jul 28, 2024
1 parent 20f9381 commit 3d79c28
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const BrandQuery = graphql(`
site {
brand(entityId: $entityId) {
name
seo {
pageTitle
metaDescription
metaKeywords
}
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions core/app/[locale]/(default)/(faceted)/brand/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {

const brand = await getBrand({ entityId: brandId });

const title = brand?.name;
if (!brand) {
return {};
}

const { pageTitle, metaDescription, metaKeywords } = brand.seo;

return {
title,
title: pageTitle || brand.name,
description: metaDescription,
keywords: metaKeywords ? metaKeywords.split(',') : null,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const CategoryPageQuery = graphql(
category(entityId: $categoryId) {
name
...BreadcrumbsFragment
seo {
pageTitle
metaDescription
metaKeywords
}
}
...CategoryTreeFragment
}
Expand Down
12 changes: 10 additions & 2 deletions core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
categoryId,
});

const title = data.category?.name;
const category = data.category;

if (!category) {
return {};
}

const { pageTitle, metaDescription, metaKeywords } = category.seo;

return {
title,
title: pageTitle || category.name,
description: metaDescription,
keywords: metaKeywords ? metaKeywords.split(',') : null,
};
}

Expand Down
2 changes: 2 additions & 0 deletions core/app/[locale]/(default)/blog/[blogId]/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const BlogPageQuery = graphql(
}
seo {
pageTitle
metaDescription
metaKeywords
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions core/app/[locale]/(default)/blog/[blogId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ export async function generateMetadata({ params: { blogId } }: Props): Promise<M
const data = await getBlogPageData({ entityId: Number(blogId) });
const blogPost = data?.content.blog?.post;

const title = blogPost?.seo.pageTitle ?? 'Blog';
if (!blogPost) {
return {};
}

const { pageTitle, metaDescription, metaKeywords } = blogPost.seo;

return {
title,
title: pageTitle || blogPost.name,
description: metaDescription,
keywords: metaKeywords ? metaKeywords.split(',') : null,
};
}

Expand Down
1 change: 1 addition & 0 deletions core/app/[locale]/(default)/blog/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const BlogPostsPageQuery = graphql(
content {
blog {
name
description
posts(first: $first, after: $after, last: $last, before: $before, filters: $filters) {
edges {
node {
Expand Down
8 changes: 5 additions & 3 deletions core/app/[locale]/(default)/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ interface Props {
export async function generateMetadata({ searchParams }: Props): Promise<Metadata> {
const blogPosts = await getBlogPosts(searchParams);

const title = blogPosts?.name ?? 'Blog';

return {
title,
title: blogPosts?.name ?? 'Blog',
description:
blogPosts?.description && blogPosts.description.length > 150
? `${blogPosts.description.substring(0, 150)}...`
: blogPosts?.description,
};
}

Expand Down
10 changes: 5 additions & 5 deletions core/app/[locale]/(default)/webpages/contact/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
const webpage = data.node?.__typename === 'ContactPage' ? data.node : null;

if (!webpage) {
notFound();
return {};
}

const { seo } = webpage;
const { pageTitle, metaDescription, metaKeywords } = webpage.seo;

return {
title: seo.pageTitle,
description: seo.metaDescription,
keywords: seo.metaKeywords,
title: pageTitle,
description: metaDescription,
keywords: metaKeywords,
};
}

Expand Down
10 changes: 5 additions & 5 deletions core/app/[locale]/(default)/webpages/normal/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export async function generateMetadata({ params: { id } }: Props): Promise<Metad
const webpage = await getWebpageData({ id });

if (!webpage) {
notFound();
return {};
}

const { seo } = webpage;
const { pageTitle, metaDescription, metaKeywords } = webpage.seo;

return {
title: seo.pageTitle,
description: seo.metaDescription,
keywords: seo.metaKeywords,
title: pageTitle || webpage.name,
description: metaDescription,
keywords: metaKeywords ? metaKeywords.split(',') : null,
};
}

Expand Down

0 comments on commit 3d79c28

Please sign in to comment.