Skip to content

Commit

Permalink
return typed data from product and collection SEO utilities (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhousedev committed Apr 6, 2023
1 parent 91f0ff4 commit 0f4d562
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-elephants-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Improve type safety in SEO data generators.
8 changes: 4 additions & 4 deletions templates/demo-store/app/lib/seo.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function productJsonLd({
product: Product;
selectedVariant: ProductVariant;
url: Request['url'];
}): SeoConfig<SeoProduct | BreadcrumbList>['jsonLd'][] {
}): SeoConfig<SeoProduct | BreadcrumbList>['jsonLd'] {
const origin = new URL(url).origin;
const variants = product.variants.nodes;
const description = truncate(
Expand Down Expand Up @@ -152,7 +152,7 @@ function product({
product: Product;
selectedVariant: ProductVariant;
url: Request['url'];
}) {
}): SeoConfig<SeoProduct | BreadcrumbList> {
const description = truncate(
product?.seo?.description ?? product?.description ?? '',
);
Expand All @@ -170,7 +170,7 @@ function collectionJsonLd({
}: {
url: Request['url'];
collection: Collection;
}): SeoConfig<CollectionPage | BreadcrumbList>['jsonLd'][] {
}): SeoConfig<CollectionPage | BreadcrumbList>['jsonLd'] {
const siteUrl = new URL(url);
const itemListElement: CollectionPage['mainEntity'] =
collection.products.nodes.map((product, index) => {
Expand Down Expand Up @@ -222,7 +222,7 @@ function collection({
}: {
collection: Collection;
url: Request['url'];
}) {
}): SeoConfig<CollectionPage | BreadcrumbList> {
return {
title: collection?.seo?.title,
description: truncate(
Expand Down

0 comments on commit 0f4d562

Please sign in to comment.