Skip to content

Commit

Permalink
SEO improvements (bigcommerce#1166)
Browse files Browse the repository at this point in the history
* Use default SEO information to set SEO defaults in layout

* Standardize generateMetadata on entities

* Fix missing instances of generateMetadata on static pages

* SEO changelog
  • Loading branch information
bookernath authored Aug 5, 2024
1 parent 0a2dfbc commit 0661e53
Showing 14 changed files with 75 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-fishes-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": minor
---

Use default SEO settings from store for pages without SEO information specified, normalize SEO implementation across pages
Original file line number Diff line number Diff line change
@@ -9,6 +9,11 @@ const BrandQuery = graphql(`
site {
brand(entityId: $entityId) {
name
seo {
pageTitle
metaDescription
metaKeywords
}
}
}
}
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
@@ -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,
};
}

Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ import BrandPage from '../page';

export default BrandPage;

export { generateMetadata } from '../page';

const BrandsQuery = graphql(`
query BrandsQuery($first: Int, $entityIds: [Int!]) {
site {
Original file line number Diff line number Diff line change
@@ -15,6 +15,11 @@ const CategoryPageQuery = graphql(
category(entityId: $categoryId) {
name
...BreadcrumbsFragment
seo {
pageTitle
metaDescription
metaKeywords
}
}
...CategoryTreeFragment
}
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
@@ -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,
};
}

Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ import CategoryPage from '../page';

export default CategoryPage;

export { generateMetadata } from '../page';

const CategoryTreeQuery = graphql(
`
query CategoryTreeQuery($categoryId: Int) {
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
@@ -26,6 +26,8 @@ const BlogPageQuery = graphql(
}
seo {
pageTitle
metaDescription
metaKeywords
}
}
}
10 changes: 8 additions & 2 deletions core/app/[locale]/(default)/blog/[blogId]/page.tsx
Original file line number Diff line number Diff line change
@@ -21,10 +21,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,
};
}

1 change: 1 addition & 0 deletions core/app/[locale]/(default)/blog/page-data.ts
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ const BlogPostsPageQuery = graphql(
content {
blog {
name
description
posts(first: $first, after: $after, last: $last, before: $before, filters: $filters) {
edges {
node {
8 changes: 5 additions & 3 deletions core/app/[locale]/(default)/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -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,
};
}

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
@@ -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,
};
}

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
@@ -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,
};
}

15 changes: 12 additions & 3 deletions core/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -26,6 +26,11 @@ const RootLayoutMetadataQuery = graphql(`
site {
settings {
storeName
seo {
pageTitle
metaDescription
metaKeywords
}
}
}
}
@@ -37,13 +42,17 @@ export async function generateMetadata(): Promise<Metadata> {
fetchOptions: { next: { revalidate } },
});

const title = data.site.settings?.storeName ?? '';
const storeName = data.site.settings?.storeName ?? '';

const { pageTitle, metaDescription, metaKeywords } = data.site.settings?.seo || {};

return {
title: {
template: `${title} - %s`,
default: title,
template: `%s - ${storeName}`,
default: pageTitle || storeName,
},
description: metaDescription,
keywords: metaKeywords ? metaKeywords.split(',') : null,
other: {
platform: 'bigcommerce.catalyst',
build_sha: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA ?? '',

0 comments on commit 0661e53

Please sign in to comment.