Created
July 7, 2019 23:27
-
-
Save converge/680bcd801ca780567f4ec27ba470fe81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// APP.JS | |
import React from 'react' | |
import './App.css' | |
import { SEO } from './seo' | |
function App() { | |
return ( | |
<div> | |
<SEO title="Home page" location="/" type="Organization" /> | |
hello | |
</div> | |
) | |
} | |
export default App | |
// --- | |
// seo.js | |
// --- | |
import React from 'react' | |
import Helmet from 'react-helmet' | |
import Thumbnail from './logo.svg' | |
// import { | |
// url, | |
// defaultTitle, | |
// defaultDescription, | |
// social, | |
// socialLinks, | |
// address, | |
// contact, | |
// legalName, | |
// foundingDate, | |
// logo, | |
// author | |
// } from './data/config' | |
const url = 'www.google.com' | |
const defaultTitle = 'www.google.com' | |
const defaultDescription = 'www.google.com' | |
const social = 'www.google.com' | |
const socialLinks = 'www.google.com' | |
const address = 'www.google.com' | |
const legalName = 'www.google.com' | |
const contact = 'www.google.com' | |
const foundingDate = 'www.google.com' | |
const logo = 'www.google.com' | |
const author = 'www.google.com' | |
export const SEO = ({ | |
title, | |
type, | |
description, | |
articleBody, | |
datePublished, | |
dateModified, | |
cover, | |
location = '', | |
readTime | |
}) => { | |
// This is Structured data that is recommended to have according to Google | |
// You can read more about it on Google's own documentation about structured data | |
// The first string is for the Article schema and the second one for the organization schema | |
const structuredDataArticle = `{ | |
"@context": "http://schema.org", | |
"@type": "${type}", | |
"mainEntityOfPage": { | |
"@type": "WebPage", | |
"@id": "https://google.com/article" | |
}, | |
"headline": "${description}", | |
"image": "${ | |
cover ? `https://smakosh.com${cover}` : `https://smakosh.com${Thumbnail}` | |
}", | |
"datePublished": "${datePublished}", | |
"dateModified": "${dateModified}", | |
"author": { | |
"@type": "Person", | |
"name": "${author}" | |
}, | |
"articleBody": "${articleBody}", | |
"publisher": { | |
"@type": "Organization", | |
"name": "${author}", | |
"logo": { | |
"@type": "ImageObject", | |
"url": "${logo}" | |
} | |
}, | |
"description": "${description}", | |
"url": "${url}${location}/?ref=smakosh.com" | |
}` | |
const structuredDataOrganization = `{ | |
"@context": "http://schema.org", | |
"@type": "${type}", | |
"legalName": "${legalName}", | |
"url": "${url}", | |
"logo": "${logo}", | |
"foundingDate": "${foundingDate}", | |
"founders": [{ | |
"@type": "Person", | |
"name": "${legalName}" | |
}], | |
"contactPoint": [{ | |
"@type": "ContactPoint", | |
"email": "${contact.email}", | |
"telephone": "${contact.phone}", | |
"contactType": "customer service" | |
}], | |
"address": { | |
"@type": "PostalAddress", | |
"addressLocality": "${address.city}", | |
"addressRegion": "${address.region}", | |
"addressCountry": "${address.country}", | |
"postalCode": "${address.zipCode}" | |
}, | |
"sameAs": [ | |
"${socialLinks.twitter}", | |
"${socialLinks.google}", | |
"${socialLinks.youtube}", | |
"${socialLinks.linkedin}", | |
"${socialLinks.instagram}", | |
"${socialLinks.github}" | |
] | |
}` | |
return ( | |
// Notice I'm using react-helmet to inject these elements within the header tag | |
<Helmet> | |
{/* The description that appears under the title of your website appears on search engines results */} | |
<meta name="description" content={description || defaultDescription} /> | |
{/* The thumbnail of your website */} | |
<meta | |
name="image" | |
content={cover ? `${url}${cover}` : `${url}${Thumbnail}`} | |
/> | |
{/* Opengraph meta tags for Facebook & LinkedIn */} | |
<meta property="og:url" content={`${url}${location}/?ref=smakosh.com`} /> | |
<meta | |
property="og:type" | |
content={type === 'NewsArticle' ? 'NewsArticle' : 'website'} | |
/> | |
<meta | |
property="og:title" | |
content={title ? `Smakosh | ${title}` : defaultTitle} | |
/> | |
<meta | |
property="og:description" | |
content={description || defaultDescription} | |
/> | |
<meta | |
property="og:image" | |
content={cover ? `${url}${cover}` : `${url}${Thumbnail}`} | |
/> | |
{/* You can get this id when you create an app id on Facebook of your Facebook page */} | |
<meta property="fb:app_id" content={social.facebook} /> | |
{/* These tags work for Twitter & Slack, notice I've included more custom tags like reading time etc... */} | |
<meta name="twitter:card" content="summary" /> | |
<meta name="twitter:creator" content={socialLinks.twitter} /> | |
<meta name="twitter:site" content={social.twitter} /> | |
<meta | |
name="twitter:title" | |
content={title ? `Smakosh | ${title}` : defaultTitle} | |
/> | |
<meta | |
name="twitter:description" | |
content={description || defaultDescription} | |
/> | |
<meta | |
name="twitter:image:src" | |
content={cover ? `${url}${cover}` : `${url}${Thumbnail}`} | |
/> | |
{type === 'NewsArticle' && ( | |
<meta name="twitter:label1" value="Reading time" /> | |
)} | |
{type === 'NewsArticle' && ( | |
<meta name="twitter:data1" value={`${readTime} min read`} /> | |
)} | |
{type === 'NewsArticle' && ( | |
<meta name="author" content="Ismail Ghallou" data-react-helmet="true" /> | |
)} | |
{type === 'NewsArticle' && ( | |
<meta | |
name="article:published_time" | |
content={datePublished} | |
data-react-helmet="true" | |
/> | |
)} | |
{/* Structured data */} | |
<script type="application/ld+json"> | |
{type === 'NewsArticle' | |
? structuredDataArticle | |
: structuredDataOrganization} | |
</script> | |
{/* Not sure if this is still relevant as Google shut down their Google+ paltform */} | |
<link rel="publisher" href={socialLinks.google} /> | |
{/* The title of your current page */} | |
<title>{title ? `Smakosh | ${title}` : defaultTitle}</title> | |
{/* Default language and direction */} | |
<html lang="en" dir="ltr" /> | |
</Helmet> | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment