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

SEO improvements #1166

Merged
merged 4 commits into from
Aug 5, 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
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
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 @@ -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 {
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import CategoryPage from '../page';

export default CategoryPage;

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

const CategoryTreeQuery = graphql(
`
query CategoryTreeQuery($categoryId: Int) {
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 @@ -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,
};
}

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
15 changes: 12 additions & 3 deletions core/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const RootLayoutMetadataQuery = graphql(`
site {
settings {
storeName
seo {
pageTitle
metaDescription
metaKeywords
}
}
}
}
Expand All @@ -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}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intentional stylistic change here - page first, store name second (same thing we do on stencil)

default: pageTitle || storeName,
},
description: metaDescription,
keywords: metaKeywords ? metaKeywords.split(',') : null,
other: {
platform: 'bigcommerce.catalyst',
build_sha: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA ?? '',
Expand Down
Loading