Skip to content

Commit

Permalink
Ported SEO component
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyvugithub committed Jan 20, 2021
1 parent 56bf34f commit 427e890
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/frontend/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
"next": "^10.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-helmet": "^6.1.0",
"react-use": "^15.3.8",
"swr": "^0.4.0"
},
"devDependencies": {
"@types/node": "^14.14.8",
"@types/react": "^16.9.51",
"@types/react-helmet": "^6.1.0",
"typescript": "^4.1.2"
}
}
47 changes: 47 additions & 0 deletions src/frontend/next/src/components/SEO.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Helmet } from 'react-helmet';
import useSiteMetadata from '../hooks/use-site-metadata';

type SEOProps = {
description?: string;
lang?: string;
meta?: Array<any>;
title?: string;
};
const SEO = ({ description, lang, meta, title }: SEOProps) => {
const siteMetadata = useSiteMetadata();
const metaDescription = description || siteMetadata.description;
const concatMeta = [
{
name: `description`,
content: metaDescription,
},
{
property: `og:title`,
content: title,
},
{
property: `og:description`,
content: metaDescription,
},
].concat(meta ?? []);

return (
<Helmet
htmlAttributes={{
lang,
}}
title={title}
titleTemplate={`%s | ${siteMetadata.title}`}
meta={concatMeta}
/>
);
};

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

export default SEO;

0 comments on commit 427e890

Please sign in to comment.