Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(website): improve SEO
- Loading branch information
Showing
5 changed files
with
225 additions
and
95 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 |
---|---|---|
@@ -1,36 +1,42 @@ | ||
const siteUrl = process.env.SITE_URL || 'https://nivo.rocks' // no trailing slash | ||
|
||
module.exports = { | ||
siteMetadata: { | ||
title: `nivo`, | ||
description: `Supercharged React dataviz components, built on top of d3js.`, | ||
author: `Raphaël Benitte`, | ||
}, | ||
plugins: [ | ||
`gatsby-plugin-react-helmet`, | ||
{ | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
name: `assets`, | ||
path: `${__dirname}/src/assets`, | ||
}, | ||
siteMetadata: { | ||
title: `nivo`, | ||
description: `Supercharged React dataviz components.`, | ||
siteUrl, | ||
og: { | ||
siteName: 'nivo', | ||
twitterCreator: '@benitteraphael', | ||
}, | ||
}, | ||
`gatsby-transformer-sharp`, | ||
`gatsby-plugin-sharp`, | ||
{ | ||
resolve: `gatsby-plugin-styled-components`, | ||
options: {}, | ||
}, | ||
{ | ||
resolve: `gatsby-plugin-manifest`, | ||
options: { | ||
name: `nivo`, | ||
short_name: `nivo`, | ||
start_url: `/`, | ||
background_color: `#3c91e8`, | ||
theme_color: `#3c91e8`, | ||
display: `minimal-ui`, | ||
icon: `src/assets/icons/nivo-icon.png`, // This path is relative to the root of the site. | ||
}, | ||
}, | ||
`gatsby-plugin-offline`, | ||
], | ||
plugins: [ | ||
`gatsby-plugin-react-helmet`, | ||
{ | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
name: `assets`, | ||
path: `${__dirname}/src/assets`, | ||
}, | ||
}, | ||
`gatsby-plugin-image`, | ||
`gatsby-transformer-sharp`, | ||
`gatsby-plugin-sharp`, | ||
{ | ||
resolve: `gatsby-plugin-styled-components`, | ||
options: {}, | ||
}, | ||
{ | ||
resolve: `gatsby-plugin-manifest`, | ||
options: { | ||
name: `nivo`, | ||
short_name: `nivo`, | ||
start_url: `/`, | ||
background_color: `#3c91e8`, | ||
theme_color: `#3c91e8`, | ||
display: `minimal-ui`, | ||
icon: `src/assets/icons/nivo-icon.png`, // This path is relative to the root of the site. | ||
}, | ||
}, | ||
], | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,150 @@ | ||
import React from 'react' | ||
import Helmet from 'react-helmet' | ||
import { useStaticQuery, graphql } from 'gatsby' | ||
import { IGatsbyImageData, getSrc } from 'gatsby-plugin-image' | ||
// @ts-ignore | ||
import { useLocation } from '@gatsbyjs/reach-router' | ||
|
||
interface Meta { | ||
name: string | ||
content: string | ||
} | ||
|
||
interface SeoProps { | ||
title: string | ||
description?: string | ||
image?: IGatsbyImageData | ||
lang?: string | ||
meta?: object[] | ||
meta?: Meta[] | ||
keywords?: string[] | ||
} | ||
|
||
interface SiteData { | ||
site: { | ||
siteMetadata: { | ||
title: string | ||
description: string | ||
siteUrl: string | ||
og: { | ||
siteName: string | ||
twitterCreator: string | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const Seo = ({ | ||
title, | ||
description = '', | ||
title: _title, | ||
description: _description, | ||
image, | ||
lang = 'en', | ||
meta = [], | ||
keywords = [], | ||
keywords, | ||
}: SeoProps) => { | ||
const { site } = useStaticQuery( | ||
const location = useLocation() | ||
|
||
const { site } = useStaticQuery<SiteData>( | ||
graphql` | ||
query SiteMetaData { | ||
site { | ||
siteMetadata { | ||
title | ||
description | ||
author | ||
siteUrl | ||
og { | ||
siteName | ||
twitterCreator | ||
} | ||
} | ||
} | ||
} | ||
` | ||
) | ||
|
||
const metaDescription = description || site.siteMetadata.description | ||
const title = _title || site.siteMetadata.title | ||
const description = _description || site.siteMetadata.description | ||
|
||
const metas: Meta[] = [ | ||
// TITLE | ||
{ | ||
name: 'og:title', | ||
content: title, | ||
}, | ||
{ | ||
name: 'twitter:title', | ||
content: title, | ||
}, | ||
// DESCRIPTION | ||
{ | ||
name: 'description', | ||
content: description, | ||
}, | ||
{ | ||
name: 'og:description', | ||
content: description, | ||
}, | ||
{ | ||
name: 'twitter:description', | ||
content: description, | ||
}, | ||
// OTHERS | ||
{ | ||
name: 'og:type', | ||
content: 'website', | ||
}, | ||
{ | ||
name: 'og:site_name', | ||
content: site.siteMetadata.og.siteName, | ||
}, | ||
{ | ||
name: 'twitter:card', | ||
content: 'summary_large_image', | ||
}, | ||
{ | ||
name: 'twitter:creator', | ||
content: site.siteMetadata.og.twitterCreator, | ||
}, | ||
{ | ||
name: 'og:url', | ||
content: `${site.siteMetadata.siteUrl}${location.pathname}`, | ||
}, | ||
] | ||
|
||
if (keywords) { | ||
metas.push({ | ||
name: `keywords`, | ||
content: keywords.join(`, `), | ||
}) | ||
} | ||
|
||
if (image) { | ||
metas.push({ | ||
name: 'og:image:width', | ||
content: `${image.width}`, | ||
}) | ||
metas.push({ | ||
name: 'og:image:height', | ||
content: `${image.height}`, | ||
}) | ||
|
||
const imageSrc = `${site.siteMetadata.siteUrl}${getSrc(image)!}` | ||
metas.push({ | ||
name: 'og:image:secure_url', | ||
content: imageSrc, | ||
}) | ||
metas.push({ | ||
name: 'twitter:image', | ||
content: imageSrc, | ||
}) | ||
} | ||
|
||
return ( | ||
<Helmet | ||
htmlAttributes={{ | ||
lang, | ||
}} | ||
title={title} | ||
titleTemplate={`%s | ${site.siteMetadata.title}`} | ||
meta={[ | ||
{ | ||
name: `description`, | ||
content: metaDescription, | ||
}, | ||
{ | ||
property: `og:title`, | ||
content: title, | ||
}, | ||
{ | ||
property: `og:description`, | ||
content: metaDescription, | ||
}, | ||
{ | ||
property: `og:type`, | ||
content: `website`, | ||
}, | ||
{ | ||
name: `twitter:card`, | ||
content: `summary`, | ||
}, | ||
{ | ||
name: `twitter:creator`, | ||
content: site.siteMetadata.author, | ||
}, | ||
{ | ||
name: `twitter:title`, | ||
content: title, | ||
}, | ||
{ | ||
name: `twitter:description`, | ||
content: metaDescription, | ||
}, | ||
...meta, | ||
].concat( | ||
keywords.length > 0 | ||
? { | ||
name: `keywords`, | ||
content: keywords.join(`, `), | ||
} | ||
: [] | ||
)} | ||
/> | ||
<Helmet titleTemplate={`%s | ${site.siteMetadata.title}`}> | ||
<html lang={lang} /> | ||
<meta charSet="utf-8" /> | ||
<title>{title}</title> | ||
{metas.map(meta => ( | ||
<meta key={meta.name} name={meta.name} content={meta.content} /> | ||
))} | ||
</Helmet> | ||
) | ||
} |
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
Oops, something went wrong.