68 lines
2.8 KiB
TypeScript
68 lines
2.8 KiB
TypeScript
import Head from 'next/head'
|
|
import type { Metadata } from 'next'
|
|
import { siteMetadata } from '@/lib/siteMetadata'
|
|
function titleText(value: Metadata['title'], fallback: string): string {
|
|
if (typeof value === 'string') return value
|
|
if (value && typeof value === 'object') {
|
|
if ('absolute' in value && value.absolute) return value.absolute
|
|
if ('default' in value && value.default) return value.default
|
|
}
|
|
return fallback
|
|
}
|
|
export function PageHead({ seo = {} }: { seo?: Metadata }) {
|
|
const title = titleText(seo.title, titleText(siteMetadata.title, 'Trump Alpha'))
|
|
const description = seo.description ?? siteMetadata.description ?? ''
|
|
const canonical =
|
|
seo.alternates?.canonical?.toString() ?? siteMetadata.alternates?.canonical?.toString()
|
|
const robots = seo.robots ?? siteMetadata.robots
|
|
const robotsText =
|
|
typeof robots === 'string'
|
|
? robots
|
|
: [
|
|
robots?.index === false ? 'noindex' : 'index',
|
|
robots?.follow === false ? 'nofollow' : 'follow',
|
|
].join(',')
|
|
const keywords = seo.keywords ?? siteMetadata.keywords
|
|
const languages = seo.alternates?.languages ?? siteMetadata.alternates?.languages
|
|
return (
|
|
<Head>
|
|
<title>{title}</title>
|
|
<meta name="description" content={description} />
|
|
<meta name="application-name" content="Trump Alpha" />
|
|
{keywords && (
|
|
<meta name="keywords" content={Array.isArray(keywords) ? keywords.join(', ') : keywords} />
|
|
)}
|
|
<meta name="author" content="Endorphin" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
|
<meta name="theme-color" content="#0f0d0a" />
|
|
<meta name="robots" content={robotsText} />
|
|
{canonical && <link rel="canonical" href={canonical} />}
|
|
{languages &&
|
|
Object.entries(languages).map(([language, value]) => (
|
|
<link
|
|
key={language}
|
|
rel="alternate"
|
|
hrefLang={language}
|
|
href={String(Array.isArray(value) ? value[0]?.url : value)}
|
|
/>
|
|
))}
|
|
<meta property="og:title" content={title} />
|
|
<meta property="og:type" content="website" />
|
|
<meta property="og:site_name" content="Trump Alpha" />
|
|
<meta property="og:locale" content="en_US" />
|
|
<meta
|
|
property="og:image"
|
|
content={`${process.env.NEXT_PUBLIC_SITE_URL || 'https://trumpsignal.com'}/opengraph-image`}
|
|
/>
|
|
<meta property="og:description" content={description} />
|
|
{canonical && <meta property="og:url" content={canonical} />}
|
|
<meta name="twitter:card" content="summary_large_image" />
|
|
<meta name="twitter:title" content={title} />
|
|
<meta name="twitter:description" content={description} />
|
|
<link rel="manifest" href="/manifest.webmanifest" />
|
|
<link rel="icon" href="/icon" />
|
|
<link rel="apple-touch-icon" href="/apple-icon" />
|
|
</Head>
|
|
)
|
|
}
|