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

fix: use unique canonical links for product pages #280

Merged
merged 1 commit into from
Aug 17, 2019
Merged
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
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