Instantly share code, notes, and snippets.
Created
October 9, 2018 00:46
Bounty metatags
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
import React from 'react'; | |
import { Helmet } from 'react-helmet'; | |
import { EXPIRED } from 'public-modules/Bounty/constants'; | |
import moment from 'moment'; | |
const SEOHeader = props => { | |
const { bounty } = props; | |
if (!bounty) { | |
return null; | |
} | |
const description = bounty.description | |
.replace('# Description', '') | |
.substring(0, 199); | |
const fulfillmentAmount = Number(bounty.calculated_fulfillmentAmount).toFixed( | |
2 | |
); | |
const usdPrice = Number(bounty.usd_price).toFixed(2); | |
const value = `${fulfillmentAmount} ${bounty.tokenSymbol} ($${usdPrice} USD)`; | |
const deadline = moment | |
.utc(bounty.deadline, 'YYYY-MM-DDThh:mm:ssZ') | |
.fromNow(true); | |
const deadlineDescription = | |
bounty.bountyStage === EXPIRED ? 'expired' : 'remaining'; | |
const deadlineText = `${deadline} ${deadlineDescription}`; | |
return ( | |
<Helmet> | |
<title>{bounty.title}</title> | |
<meta name="description" content={description} /> | |
<meta name="twitter:card" value="summary_large_image" /> | |
<meta name="twitter:site" content="@ethbounties" /> | |
<meta name="twitter:title" content={bounty.title} /> | |
<meta name="twitter:description" content={description} /> | |
<meta name="twitter:creator" content="@ethbounties" /> | |
<meta name="twitter:image:src" content={bounty.image_preview} /> | |
<meta name="twitter:label1" value="Bounty Payout" /> | |
<meta name="twitter:data1" value={value} /> | |
<meta name="twitter:label2" value="Deadline to Submit" /> | |
<meta name="twitter:data2" value={deadlineText} /> | |
<meta property="og:title" content={bounty.title} /> | |
<meta property="og:type" content="article" /> | |
<meta property="og:url" content={window.location.href} /> | |
<meta property="og:image:secure_url" content={bounty.image_preview} /> | |
<meta property="og:description" content={description} /> | |
</Helmet> | |
); | |
}; | |
export default SEOHeader; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment