From 0f4d562a2129e8e03ed123dc572a14a72e487a1b Mon Sep 17 00:00:00 2001 From: David House Date: Thu, 6 Apr 2023 12:58:05 -0400 Subject: [PATCH] return typed data from product and collection SEO utilities (#763) --- .changeset/small-elephants-jam.md | 5 +++++ templates/demo-store/app/lib/seo.server.ts | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changeset/small-elephants-jam.md diff --git a/.changeset/small-elephants-jam.md b/.changeset/small-elephants-jam.md new file mode 100644 index 0000000000..d269510ce3 --- /dev/null +++ b/.changeset/small-elephants-jam.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli-hydrogen': patch +--- + +Improve type safety in SEO data generators. diff --git a/templates/demo-store/app/lib/seo.server.ts b/templates/demo-store/app/lib/seo.server.ts index 42a946b5ad..06a267dac2 100644 --- a/templates/demo-store/app/lib/seo.server.ts +++ b/templates/demo-store/app/lib/seo.server.ts @@ -85,7 +85,7 @@ function productJsonLd({ product: Product; selectedVariant: ProductVariant; url: Request['url']; -}): SeoConfig['jsonLd'][] { +}): SeoConfig['jsonLd'] { const origin = new URL(url).origin; const variants = product.variants.nodes; const description = truncate( @@ -152,7 +152,7 @@ function product({ product: Product; selectedVariant: ProductVariant; url: Request['url']; -}) { +}): SeoConfig { const description = truncate( product?.seo?.description ?? product?.description ?? '', ); @@ -170,7 +170,7 @@ function collectionJsonLd({ }: { url: Request['url']; collection: Collection; -}): SeoConfig['jsonLd'][] { +}): SeoConfig['jsonLd'] { const siteUrl = new URL(url); const itemListElement: CollectionPage['mainEntity'] = collection.products.nodes.map((product, index) => { @@ -222,7 +222,7 @@ function collection({ }: { collection: Collection; url: Request['url']; -}) { +}): SeoConfig { return { title: collection?.seo?.title, description: truncate(