forked from ryanwiemer/gatsby-starter-gcn
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidated most meta tags to the SEO component Includes squashed pt-pt3 commits from other PR
- Loading branch information
1 parent
d08f574
commit c40a71e
Showing
8 changed files
with
222 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import React, { Component } from 'react' | ||
import Helmet from 'react-helmet' | ||
import config from '../utils/siteConfig' | ||
|
||
class SEO extends Component { | ||
render() { | ||
const { postNode, pagePath, postSEO, pageSEO } = this.props | ||
let title | ||
let description | ||
let image | ||
let imgWidth | ||
let imgHeight | ||
let pageUrl | ||
|
||
// Set Default OpenGraph Parameters for Fallback | ||
title = config.siteTitle | ||
description = config.siteDescription | ||
image = config.siteUrl + config.siteLogo | ||
imgWidth = 512 | ||
imgHeight = 512 | ||
pageUrl = config.siteUrl | ||
|
||
// Replace with Page Parameters if post or page | ||
if (postSEO || pageSEO) { | ||
title = postNode.title | ||
description = | ||
postNode.metaDescription === null | ||
? postNode.body.childMarkdownRemark.excerpt | ||
: postNode.metaDescription | ||
|
||
pageUrl = config.siteUrl + '/' + pagePath + '/' | ||
} | ||
// Use Hero Image for OpenGraph | ||
if (postSEO) { | ||
image = 'https:' + postNode.heroImage.ogimg.src | ||
imgWidth = postNode.heroImage.ogimg.width | ||
imgHeight = postNode.heroImage.ogimg.height | ||
} | ||
|
||
// Default Website Schema | ||
const schemaOrgJSONLD = [ | ||
{ | ||
'@context': 'http://schema.org', | ||
'@type': 'WebSite', | ||
url: config.siteUrl, | ||
name: config.siteTitle, | ||
alternateName: config.siteTitleAlt ? config.siteTitleAlt : '', | ||
}, | ||
] | ||
|
||
// Blog Post Schema | ||
if (postSEO) { | ||
schemaOrgJSONLD.push( | ||
{ | ||
'@context': 'http://schema.org', | ||
'@type': 'BreadcrumbList', | ||
itemListElement: [ | ||
{ | ||
'@type': 'ListItem', | ||
position: 1, | ||
item: { | ||
'@id': config.siteUrl, | ||
name: config.siteTitle, | ||
}, | ||
}, | ||
{ | ||
'@type': 'ListItem', | ||
position: 2, | ||
item: { | ||
'@id': pageUrl, | ||
name: title, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
'@context': 'http://schema.org', | ||
'@type': 'BlogPosting', | ||
url: pageUrl, | ||
name: title, | ||
alternateName: config.siteTitleAlt ? config.siteTitleAlt : '', | ||
headline: title, | ||
image: { | ||
'@type': 'ImageObject', | ||
url: image, | ||
width: imgWidth, | ||
height: imgHeight, | ||
}, | ||
author: { | ||
'@type': 'Person', | ||
name: config.author, | ||
url: config.authorUrl, | ||
}, | ||
publisher: { | ||
'@type': 'Organization', | ||
name: config.publisher, | ||
url: config.siteUrl, | ||
}, | ||
datePublished: postNode.publishDateISO, | ||
mainEntityOfPage: pageUrl, | ||
} | ||
) | ||
} | ||
|
||
// Page SEO Schema | ||
if (pageSEO) { | ||
schemaOrgJSONLD.push({ | ||
'@context': 'http://schema.org', | ||
'@type': 'WebPage', | ||
url: pageUrl, | ||
name: title, | ||
}) | ||
} | ||
|
||
return ( | ||
<Helmet> | ||
{/* General tags */} | ||
<meta name="image" content={image} /> | ||
<meta name="description" content={description} /> | ||
|
||
{/* Schema.org tags */} | ||
<script type="application/ld+json"> | ||
{JSON.stringify(schemaOrgJSONLD)} | ||
</script> | ||
|
||
{/* OpenGraph tags */} | ||
<meta property="og:title" content={title} /> | ||
{postSEO ? <meta property="og:type" content="article" /> : null} | ||
|
||
<meta property="og:url" content={pageUrl} /> | ||
<meta property="og:image" content={image} /> | ||
<meta property="og:image:width" content={imgWidth} /> | ||
<meta property="og:image:height" content={imgHeight} /> | ||
<meta property="og:description" content={description} /> | ||
|
||
{/* Twitter Card tags */} | ||
<meta name="twitter:card" content="summary_large_image" /> | ||
<meta | ||
name="twitter:creator" | ||
content={config.userTwitter ? config.userTwitter : ''} | ||
/> | ||
<meta name="twitter:title" content={title} /> | ||
<meta name="twitter:image" content={image} /> | ||
<meta name="twitter:description" content={description} /> | ||
</Helmet> | ||
) | ||
} | ||
} | ||
|
||
export default SEO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.