-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor meta tags into separate component and add default thumbnail …
…/ image (#359)
- Loading branch information
Showing
6 changed files
with
62 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from "react"; | ||
import Head from "next/head"; | ||
|
||
type MetaHeaderProps = { | ||
title?: string; | ||
description?: string; | ||
image?: string; | ||
twitterCard?: string; | ||
children?: React.ReactNode; | ||
}; | ||
|
||
export const MetaHeader = ({ | ||
title = "Scaffold-ETH 2 App", | ||
description = "Built with 🏗 Scaffold-ETH 2", | ||
image = "thumbnail.png", | ||
twitterCard = "summary_large_image", | ||
children, | ||
}: MetaHeaderProps) => { | ||
// Images must have an absolute path to work properly on Twitter and OG | ||
const absoluteImagePath = typeof window !== "undefined" ? `${window.location.origin}/${image}` : undefined; | ||
|
||
return ( | ||
<Head> | ||
{title && ( | ||
<> | ||
<title>{title}</title> | ||
<meta property="og:title" content={title} /> | ||
<meta name="twitter:title" content={title} /> | ||
</> | ||
)} | ||
{description && ( | ||
<> | ||
<meta name="description" content={description} /> | ||
<meta property="og:description" content={description} /> | ||
<meta name="twitter:description" content={description} /> | ||
</> | ||
)} | ||
{absoluteImagePath && ( | ||
<> | ||
<meta property="og:image" content={absoluteImagePath} /> | ||
<meta name="twitter:image" content={absoluteImagePath} /> | ||
</> | ||
)} | ||
{twitterCard && <meta name="twitter:card" content={twitterCard} />} | ||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon.png" /> | ||
{children} | ||
</Head> | ||
); | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.