2022-05-26 22:22:44 +00:00
|
|
|
import { ReactNode } from 'react'
|
2021-12-16 18:40:23 +00:00
|
|
|
import Head from 'next/head'
|
2022-08-04 21:27:02 +00:00
|
|
|
import { Challenge } from 'common/challenge'
|
2021-12-16 18:40:23 +00:00
|
|
|
|
2022-01-10 07:05:24 +00:00
|
|
|
export type OgCardProps = {
|
|
|
|
question: string
|
2022-02-18 00:34:11 +00:00
|
|
|
probability?: string
|
2022-01-10 07:05:24 +00:00
|
|
|
metadata: string
|
|
|
|
creatorName: string
|
|
|
|
creatorUsername: string
|
2022-05-06 18:29:15 +00:00
|
|
|
creatorAvatarUrl?: string
|
2022-08-05 12:56:10 +00:00
|
|
|
numericValue?: string
|
2022-01-10 07:05:24 +00:00
|
|
|
}
|
|
|
|
|
2022-08-04 21:27:02 +00:00
|
|
|
function buildCardUrl(props: OgCardProps, challenge?: Challenge) {
|
|
|
|
const {
|
|
|
|
creatorAmount,
|
|
|
|
acceptances,
|
|
|
|
acceptorAmount,
|
|
|
|
creatorOutcome,
|
|
|
|
acceptorOutcome,
|
|
|
|
} = challenge || {}
|
|
|
|
const { userName, userAvatarUrl } = acceptances?.[0] ?? {}
|
|
|
|
|
2022-02-18 00:34:11 +00:00
|
|
|
const probabilityParam =
|
|
|
|
props.probability === undefined
|
|
|
|
? ''
|
|
|
|
: `&probability=${encodeURIComponent(props.probability ?? '')}`
|
2022-08-05 12:56:10 +00:00
|
|
|
|
|
|
|
const numericValueParam =
|
|
|
|
props.numericValue === undefined
|
|
|
|
? ''
|
|
|
|
: `&numericValue=${encodeURIComponent(props.numericValue ?? '')}`
|
|
|
|
|
2022-05-06 18:29:15 +00:00
|
|
|
const creatorAvatarUrlParam =
|
|
|
|
props.creatorAvatarUrl === undefined
|
|
|
|
? ''
|
|
|
|
: `&creatorAvatarUrl=${encodeURIComponent(props.creatorAvatarUrl ?? '')}`
|
|
|
|
|
2022-08-04 21:27:02 +00:00
|
|
|
const challengeUrlParams = challenge
|
|
|
|
? `&creatorAmount=${creatorAmount}&creatorOutcome=${creatorOutcome}` +
|
|
|
|
`&challengerAmount=${acceptorAmount}&challengerOutcome=${acceptorOutcome}` +
|
|
|
|
`&acceptedName=${userName ?? ''}&acceptedAvatarUrl=${userAvatarUrl ?? ''}`
|
|
|
|
: ''
|
|
|
|
|
2022-01-10 07:05:24 +00:00
|
|
|
// URL encode each of the props, then add them as query params
|
|
|
|
return (
|
|
|
|
`https://manifold-og-image.vercel.app/m.png` +
|
|
|
|
`?question=${encodeURIComponent(props.question)}` +
|
2022-02-18 00:34:11 +00:00
|
|
|
probabilityParam +
|
2022-08-05 12:56:10 +00:00
|
|
|
numericValueParam +
|
2022-01-10 07:05:24 +00:00
|
|
|
`&metadata=${encodeURIComponent(props.metadata)}` +
|
|
|
|
`&creatorName=${encodeURIComponent(props.creatorName)}` +
|
2022-05-06 18:29:15 +00:00
|
|
|
creatorAvatarUrlParam +
|
2022-08-04 21:27:02 +00:00
|
|
|
`&creatorUsername=${encodeURIComponent(props.creatorUsername)}` +
|
|
|
|
challengeUrlParams
|
2022-01-10 07:05:24 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-16 18:40:23 +00:00
|
|
|
export function SEO(props: {
|
|
|
|
title: string
|
|
|
|
description: string
|
|
|
|
url?: string
|
2022-05-26 22:22:44 +00:00
|
|
|
children?: ReactNode
|
2022-01-10 07:05:24 +00:00
|
|
|
ogCardProps?: OgCardProps
|
2022-08-04 21:27:02 +00:00
|
|
|
challenge?: Challenge
|
2021-12-16 18:40:23 +00:00
|
|
|
}) {
|
2022-08-04 21:27:02 +00:00
|
|
|
const { title, description, url, children, ogCardProps, challenge } = props
|
2021-12-16 18:40:23 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Head>
|
2022-01-06 18:48:30 +00:00
|
|
|
<title>{title} | Manifold Markets</title>
|
2021-12-16 18:40:23 +00:00
|
|
|
|
|
|
|
<meta
|
|
|
|
property="og:title"
|
|
|
|
name="twitter:title"
|
|
|
|
content={title}
|
|
|
|
key="title"
|
|
|
|
/>
|
|
|
|
<meta name="description" content={description} key="description1" />
|
|
|
|
<meta
|
|
|
|
property="og:description"
|
|
|
|
name="twitter:description"
|
|
|
|
content={description}
|
|
|
|
key="description2"
|
|
|
|
/>
|
|
|
|
|
|
|
|
{url && (
|
|
|
|
<meta
|
|
|
|
property="og:url"
|
2022-01-06 18:48:30 +00:00
|
|
|
content={'https://manifold.markets' + url}
|
2021-12-16 18:40:23 +00:00
|
|
|
key="url"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2022-01-10 07:05:24 +00:00
|
|
|
{ogCardProps && (
|
|
|
|
<>
|
|
|
|
<meta
|
|
|
|
property="og:image"
|
2022-08-04 21:27:02 +00:00
|
|
|
content={buildCardUrl(ogCardProps, challenge)}
|
2022-01-10 07:05:24 +00:00
|
|
|
key="image1"
|
|
|
|
/>
|
|
|
|
<meta name="twitter:card" content="summary_large_image" key="card" />
|
|
|
|
<meta
|
|
|
|
name="twitter:image"
|
2022-08-04 21:27:02 +00:00
|
|
|
content={buildCardUrl(ogCardProps, challenge)}
|
2022-01-10 07:05:24 +00:00
|
|
|
key="image2"
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
2021-12-16 18:40:23 +00:00
|
|
|
{children}
|
|
|
|
</Head>
|
|
|
|
)
|
|
|
|
}
|