This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from mirumee/meta_tags
Add OpenGraph and Meta tags
- Loading branch information
Showing
43 changed files
with
677 additions
and
396 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from "react"; | ||
|
||
import { META_DEFAULTS } from "../../core/config"; | ||
import { default as MetaConsumer } from "./consumer"; | ||
import { MetaContextInterface, Provider as MetaProvider } from "./context"; | ||
|
||
const removeEmpty = obj => { | ||
const newObj = {}; | ||
Object.keys(obj).forEach(prop => { | ||
if (obj[prop] && obj[prop] !== "") { | ||
newObj[prop] = obj[prop]; | ||
} | ||
}); | ||
return newObj; | ||
}; | ||
|
||
interface MetaWrapperProps { | ||
meta: MetaContextInterface; | ||
children: React.ReactNode; | ||
} | ||
|
||
const MetaWrapper: React.SFC<MetaWrapperProps> = ({ children, meta }) => ( | ||
<MetaProvider value={{ ...META_DEFAULTS, ...removeEmpty(meta) }}> | ||
<MetaConsumer>{children}</MetaConsumer> | ||
</MetaProvider> | ||
); | ||
|
||
export default MetaWrapper; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as React from "react"; | ||
import { Helmet } from "react-helmet"; | ||
|
||
import { Consumer as MetaConsumer } from "./context"; | ||
|
||
const Consumer: React.SFC<{ children?: React.ReactNode }> = ({ children }) => ( | ||
<MetaConsumer> | ||
{({ title, description, image, type, url, custom }) => ( | ||
<> | ||
<Helmet | ||
title={title} | ||
meta={[ | ||
{ name: "description", content: description }, | ||
{ property: "og:url", content: url }, | ||
{ property: "og:type", content: type }, | ||
{ property: "og:image", content: image }, | ||
...custom | ||
]} | ||
/> | ||
{children} | ||
</> | ||
)} | ||
</MetaConsumer> | ||
); | ||
|
||
export default Consumer; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as React from "react"; | ||
import { META_DEFAULTS } from "../../core/config"; | ||
|
||
type MetaProps = JSX.IntrinsicElements["meta"]; | ||
|
||
export interface MetaContextInterface { | ||
title?: string; | ||
description?: string; | ||
url?: string; | ||
image?: string; | ||
type?: string; | ||
custom?: MetaProps[]; | ||
} | ||
|
||
export const { Provider, Consumer } = React.createContext<MetaContextInterface>( | ||
META_DEFAULTS | ||
); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { Provider as MetaProvider, MetaContextInterface } from "./context"; | ||
export { default as MetaConsumer } from "./consumer"; | ||
export { default as MetaWrapper } from "./MetaWrapper"; |
Oops, something went wrong.