Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
seo: rewrite SEO component
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithpabbati committed Oct 5, 2020
1 parent b8e4b12 commit 87482f5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
72 changes: 39 additions & 33 deletions src/components/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from 'react';
import PropTypes from 'prop-types';
import Helmet from 'react-helmet';
import { useStaticQuery, graphql } from 'gatsby';
import SEOImage from '../images/logos/amfoss_seo.png';

function SEO({ author, description, lang, meta, image, title, type, keywords }) {
function SEO({ description, lang, meta, image, title, keywords }) {
const { site } = useStaticQuery(
graphql`
query {
Expand All @@ -20,6 +21,7 @@ function SEO({ author, description, lang, meta, image, title, type, keywords })
);

const metaDescription = description || site.siteMetadata.description;
const metaImage = image ? image : SEOImage;

return (
<Helmet
Expand All @@ -29,41 +31,29 @@ function SEO({ author, description, lang, meta, image, title, type, keywords })
title={title}
titleTemplate={`%s | ${site.siteMetadata.title}`}
meta={[
{
name: `author`,
content: author,
},
{
name: `description`,
content: metaDescription,
},
{
name: `keywords`,
content: keywords ? keywords : metaDescription,
},
{
name: `category`,
content: type,
},
{
property: `og:title`,
content: title,
},
{
property: `og:url`,
content: site.siteMetadata.siteUrl,
},
{
property: `og:description`,
content: metaDescription,
},
{
property: `og:type`,
content: type,
},
{
name: `twitter:card`,
content: `summary_large_image`,
content: `website`,
},
{
name: `twitter:creator`,
content: author ? author : site.siteMetadata.author,
content: `@${site.siteMetadata.author}`,
},
{
name: `twitter:title`,
Expand All @@ -73,24 +63,44 @@ function SEO({ author, description, lang, meta, image, title, type, keywords })
name: `twitter:description`,
content: metaDescription,
},
{
name: 'hosting-dcv',
content:
'6e16d6248fca96228ab0494ed816bb59-501e7dcc94812d01473d63d948b9df96',
},
]
.concat(
image
metaImage
? [
{
property: 'og:image',
content: image,
property: `og:image`,
content: metaImage,
},
{
name: 'twitter:image',
content: image,
property: `og:image:alt`,
content: title,
},
{
property: 'og:image:width',
content: metaImage.width,
},
{
property: 'og:image:height',
content: metaImage.height,
},
{
name: `twitter:card`,
content: `summary_large_image`,
},
]
: [
{
name: `twitter:card`,
content: `summary`,
},
]
)
.concat(
keywords.length > 0
? {
name: `keywords`,
content: keywords,
}
: []
)
.concat(meta)}
Expand All @@ -99,22 +109,18 @@ function SEO({ author, description, lang, meta, image, title, type, keywords })
}

SEO.defaultProps = {
author: ``,
lang: `en`,
meta: [],
description: ``,
type: `website`,
keywords: ``,
image: ``,
};

SEO.propTypes = {
author: PropTypes.string,
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string.isRequired,
type: PropTypes.string,
keywords: PropTypes.string,
image: PropTypes.string,
};
Expand Down
Binary file added src/images/logos/amfoss_seo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/templates/articleTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default function ArticleTemplate(props) {
title={data.title}
slug={data.slug}
description={data.description}
author={data.author.fullName}
keywords={data.tags ? data.tags.join(', ') : null}
image={`${site.siteMetadata.siteUrl}/news/${data.slug}/seo.jpg`}
/>
Expand Down
1 change: 0 additions & 1 deletion src/templates/blogTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default function BlogTemplate(props) {
title={data.title}
slug={data.slug}
description={data.description}
author={data.author.fullName}
keywords={data.tags ? data.tags.join(', ') : null}
image={`${site.siteMetadata.siteUrl}/news/${data.slug}/seo.jpg`}
/>
Expand Down

0 comments on commit 87482f5

Please sign in to comment.