Skip to content

Commit

Permalink
fix: use unique canonical links for product pages (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahdayan authored and Jason Lengstorf committed Aug 17, 2019
1 parent f965a25 commit f5ffdeb
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/templates/ProductPageTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ const removeCareInstructions = desc =>

const ProductPageTemplate = props => {
const {
site,
shopifyProduct: product,
shopifyProduct: { title, description: fullDescription, handle }
} = props.data;
data: {
site,
shopifyProduct: product,
shopifyProduct: { title, description: fullDescription, handle }
},
location: { pathname }
} = props;
const {
siteMetadata: { siteUrl }
} = site;

const description = removeCareInstructions(fullDescription);
const image = product.images[0].localFile.childImageSharp.fluid.src;
const canonical = `${siteUrl}${pathname}`;

return (
<InterfaceContext.Consumer>
Expand All @@ -32,21 +39,16 @@ const ProductPageTemplate = props => {
<title>{title}</title>

<meta name="description" content={description} />
<link rel="canonical" href={canonical} />

<meta
property="og:url"
content={`${site.siteMetadata.siteUrl}/product/${handle}`}
/>
<meta property="og:url" content={`${siteUrl}/product/${handle}`} />
<meta property="og:locale" content="en" />
<meta property="og:title" content={title} />
<meta property="og:site_name" content="Gatsby Swag Store" />
<meta property="og:description" content={description} />

{/* TODO: add the image */}
<meta
property="og:image"
content={`${site.siteMetadata.siteUrl}${image}`}
/>
<meta property="og:image" content={`${siteUrl}${image}`} />
<meta property="og:image:alt" content={title} />
<meta property="og:image:width" content="600" />
<meta property="og:image:height" content="600" />
Expand Down

0 comments on commit f5ffdeb

Please sign in to comment.