Skip to content

Commit

Permalink
Merge pull request #24 from marzeelabs/feature/23_fix-og-and-twitter-…
Browse files Browse the repository at this point in the history
…meta-tags

#23 updated og and twitter meta tags
  • Loading branch information
JessicaNovo committed Apr 13, 2020
2 parents d2420fb + 185826d commit b2b8d0b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 70 deletions.
6 changes: 0 additions & 6 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ module.exports = {
siteUrl,
},
plugins: [
{
resolve: 'gatsby-plugin-canonical-urls',
options: {
siteUrl,
},
},
{
resolve: 'gatsby-plugin-alias-imports',
options: {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"gatsby": "^2.19.45",
"gatsby-image": "^2.2.44",
"gatsby-plugin-alias-imports": "^1.0.5",
"gatsby-plugin-canonical-urls": "^2.2.1",
"gatsby-plugin-google-analytics": "^2.2.2",
"gatsby-plugin-manifest": "^2.2.48",
"gatsby-plugin-material-ui": "^2.1.6",
Expand Down
79 changes: 29 additions & 50 deletions src/components/SEO.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
*/

import React from 'react';
import { arrayOf, object, string } from 'prop-types';
import { node, string } from 'prop-types';
import Helmet from 'react-helmet';
import { useStaticQuery, graphql } from 'gatsby';

const SEO = ({
children,
description,
lang,
meta,
location,
title,
}) => {
const { site, metaImageDefault } = useStaticQuery(
Expand Down Expand Up @@ -41,63 +42,41 @@ const SEO = ({

const metaDescription = description || site.siteMetadata.description;

// the image url has to be an absolute url with http:// or https://
// relative links do not work
const metaImage = site.siteMetadata.siteUrl.concat(metaImageDefault.childImageSharp.fixed.src);
const canonical = `${site.siteMetadata.siteUrl}${location.pathname}`;
const metaImage = `${site.siteMetadata.siteUrl}${metaImageDefault.childImageSharp.fixed.src}`;

return (
<Helmet
htmlAttributes={ { lang } }
title={ title }
titleTemplate={ `%s | ${site.siteMetadata.title}` }
meta={ [
{
name: 'description',
content: metaDescription,
},
{
property: 'og:description',
name: 'twitter:description',
content: metaDescription,
},
{
property: 'og:title',
name: 'twitter:title',
content: title,
},
{
property: 'og:image',
name: 'twitter:image',
content: metaImage,
},
{
property: 'og:type',
content: 'website',
},
{
name: 'twitter:card',
content: 'summary_large_image',
},
{
name: 'twitter:creator',
content: site.siteMetadata.author,
},
].concat(meta) }
/>
<Helmet titleTemplate={ `%s | ${site.siteMetadata.title}` }>
<html lang={ lang } />
<link rel="canonical" href={ canonical } />
<meta property="og:url" content={ canonical } />
<title>{ title }</title>
<meta property="og:title" content={ title } />
<meta name="twitter:title" content={ title } />
<meta name="description" content={ metaDescription } />
<meta property="og:description" content={ metaDescription } />
<meta name="twitter:description" content={ metaDescription } />
<meta property="og:image" content={ metaImage } />
<meta name="twitter:image" content={ metaImage } />
<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:creator" content={ site.siteMetadata.author } />
{ children }
</Helmet>
);
};

SEO.defaultProps = {
lang: 'en',
meta: [],
description: '',
};

SEO.propTypes = {
children: node,
description: string,
lang: string,
meta: arrayOf(object),
title: string.isRequired,
};

SEO.defaultProps = {
children: null,
lang: 'pt',
description: '',
};

export default SEO;
4 changes: 2 additions & 2 deletions src/pages/404.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Link } from 'gatsby';
import PageWrapper from 'Layouts/PageWrapper';
import SEO from '../components/SEO';

const NotFoundPage = () => (
const NotFoundPage = ({ location }) => (
<PageWrapper>
<SEO title="404: Not found" />
<SEO title="404: Not found" location={ location } />
<h1>NOT FOUND</h1>
<p>You just hit a route that doesn&#39;t exist....</p>
<Link to="/">
Expand Down
4 changes: 2 additions & 2 deletions src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import PageWrapper from 'Layouts/PageWrapper';

import useStyles from 'Styles/pages/home';

const IndexPage = () => {
const IndexPage = ({ location }) => {
const classes = useStyles();

return (
<PageWrapper>
<SEO title="Compra aos pequenos" />
<SEO title="Compra aos pequenos" location={ location } />
<Hero
background="homeBg"
callToAction={ {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/shops.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import Shops from 'Components/Shops/Shops';

import PageWrapper from 'Layouts/PageWrapper';

export default () => (
export default ({ location }) => (
<PageWrapper>
<SEO title="Lista de Negócios" />
<SEO title="Lista de Negócios" location={ location } />
<Hero background="shopsBg" />
<Shops />
</PageWrapper>
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5627,13 +5627,6 @@ gatsby-plugin-alias-imports@^1.0.5:
dependencies:
"@babel/runtime" "^7.2.0"

gatsby-plugin-canonical-urls@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/gatsby-plugin-canonical-urls/-/gatsby-plugin-canonical-urls-2.2.1.tgz#43d89aa8724dcac5c960bb57f33132c7c09ff05e"
integrity sha512-bbNfFlyZ1ksSbJ0iA+IPyybgcIaFF9EK+bEWTK01YqUEgUuosS+pY553qJ8AakxERaAgwxn1WwsovmeNgsOH3A==
dependencies:
"@babel/runtime" "^7.8.7"

gatsby-plugin-google-analytics@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/gatsby-plugin-google-analytics/-/gatsby-plugin-google-analytics-2.2.2.tgz#b4d2a10e1863bb4c92084a1778c4a2aab53292f5"
Expand Down

0 comments on commit b2b8d0b

Please sign in to comment.