import { ReactNode } from 'react' import Head from 'next/head' import { Challenge } from 'common/challenge' export type OgCardProps = { question: string probability?: string metadata: string creatorName: string creatorUsername: string creatorAvatarUrl?: string numericValue?: string } function buildCardUrl(props: OgCardProps, challenge?: Challenge) { const { creatorAmount, acceptances, acceptorAmount, creatorOutcome, acceptorOutcome, } = challenge || {} const { userName, userAvatarUrl } = acceptances?.[0] ?? {} const probabilityParam = props.probability === undefined ? '' : `&probability=${encodeURIComponent(props.probability ?? '')}` const numericValueParam = props.numericValue === undefined ? '' : `&numericValue=${encodeURIComponent(props.numericValue ?? '')}` const creatorAvatarUrlParam = props.creatorAvatarUrl === undefined ? '' : `&creatorAvatarUrl=${encodeURIComponent(props.creatorAvatarUrl ?? '')}` const challengeUrlParams = challenge ? `&creatorAmount=${creatorAmount}&creatorOutcome=${creatorOutcome}` + `&challengerAmount=${acceptorAmount}&challengerOutcome=${acceptorOutcome}` + `&acceptedName=${userName ?? ''}&acceptedAvatarUrl=${userAvatarUrl ?? ''}` : '' // 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)}` + probabilityParam + numericValueParam + `&metadata=${encodeURIComponent(props.metadata)}` + `&creatorName=${encodeURIComponent(props.creatorName)}` + creatorAvatarUrlParam + `&creatorUsername=${encodeURIComponent(props.creatorUsername)}` + challengeUrlParams ) } export function SEO(props: { title: string description: string url?: string children?: ReactNode ogCardProps?: OgCardProps challenge?: Challenge }) { const { title, description, url, children, ogCardProps, challenge } = props return ( {title} | Manifold Markets {url && ( )} {ogCardProps && ( <> )} {children} ) }