Unverified Commit 2bf2c9c5 authored by Josh Story's avatar Josh Story Committed by GitHub

Simplify metadata tag rendering to flat imperative style (#90209)

Replace the layered abstraction (Meta, MetaFilter, MultiMeta,
ExtendMeta, and 12 category component functions across 5 files) with a
single flat function that builds a tags array using explicit if-checks
and for-loops. Every meta/link tag is now visible as literal JSX at the
call site. OG image/video/audio properties and AppLinks fields are
enumerated explicitly rather than iterated generically from object keys.
Keys are assigned directly on each element at push time, eliminating the
cloneElement keying pass.
parent 56adc02e
import type { ResolvedMetadata } from '../types/metadata-interface'
import type { AlternateLinkDescriptor } from '../types/alternative-urls-types'
import React from 'react'
import { MetaFilter } from './meta'
function AlternateLink({
descriptor,
...props
}: {
descriptor: AlternateLinkDescriptor
} & React.LinkHTMLAttributes<HTMLLinkElement>) {
if (!descriptor.url) return null
return (
<link
{...props}
{...(descriptor.title && { title: descriptor.title })}
href={descriptor.url.toString()}
/>
)
}
export function AlternatesMetadata({
alternates,
}: {
alternates: ResolvedMetadata['alternates']
}) {
if (!alternates) return null
const { canonical, languages, media, types } = alternates
return MetaFilter([
canonical
? AlternateLink({ rel: 'canonical', descriptor: canonical })
: null,
languages
? Object.entries(languages).flatMap(([locale, descriptors]) =>
descriptors?.map((descriptor) =>
AlternateLink({ rel: 'alternate', hrefLang: locale, descriptor })
)
)
: null,
media
? Object.entries(media).flatMap(([mediaName, descriptors]) =>
descriptors?.map((descriptor) =>
AlternateLink({ rel: 'alternate', media: mediaName, descriptor })
)
)
: null,
types
? Object.entries(types).flatMap(([type, descriptors]) =>
descriptors?.map((descriptor) =>
AlternateLink({ rel: 'alternate', type, descriptor })
)
)
: null,
])
}
import type {
ResolvedMetadata,
ResolvedViewport,
Viewport,
} from '../types/metadata-interface'
import type { ViewportLayout } from '../types/extra-types'
import { Meta, MetaFilter, MultiMeta } from './meta'
import { ViewportMetaKeys } from '../constants'
import { getOrigin } from './utils'
// convert viewport object to string for viewport meta tag
function resolveViewportLayout(viewport: Viewport) {
let resolved: string | null = null
if (viewport && typeof viewport === 'object') {
resolved = ''
for (const viewportKey_ in ViewportMetaKeys) {
const viewportKey = viewportKey_ as keyof ViewportLayout
if (viewportKey in viewport) {
let value = viewport[viewportKey]
if (typeof value === 'boolean') {
value = value ? 'yes' : 'no'
} else if (!value && viewportKey === 'initialScale') {
value = undefined
}
if (value) {
if (resolved) resolved += ', '
resolved += `${ViewportMetaKeys[viewportKey]}=${value}`
}
}
}
}
return resolved
}
export function ViewportMeta({ viewport }: { viewport: ResolvedViewport }) {
return MetaFilter([
<meta charSet="utf-8" />,
Meta({ name: 'viewport', content: resolveViewportLayout(viewport) }),
...(viewport.themeColor
? viewport.themeColor.map((themeColor) =>
Meta({
name: 'theme-color',
content: themeColor.color,
media: themeColor.media,
})
)
: []),
Meta({ name: 'color-scheme', content: viewport.colorScheme }),
])
}
export function BasicMeta({ metadata }: { metadata: ResolvedMetadata }) {
const manifestOrigin = metadata.manifest
? getOrigin(metadata.manifest)
: undefined
return MetaFilter([
metadata.title !== null && metadata.title.absolute ? (
<title>{metadata.title.absolute}</title>
) : null,
Meta({ name: 'description', content: metadata.description }),
Meta({ name: 'application-name', content: metadata.applicationName }),
...(metadata.authors
? metadata.authors.map((author) => [
author.url ? (
<link rel="author" href={author.url.toString()} />
) : null,
Meta({ name: 'author', content: author.name }),
])
: []),
metadata.manifest ? (
<link
rel="manifest"
href={metadata.manifest.toString()}
// If it's same origin, and it's a preview deployment,
// including credentials for manifest request.
crossOrigin={
!manifestOrigin && process.env.VERCEL_ENV === 'preview'
? 'use-credentials'
: undefined
}
/>
) : null,
Meta({ name: 'generator', content: metadata.generator }),
Meta({ name: 'keywords', content: metadata.keywords?.join(',') }),
Meta({ name: 'referrer', content: metadata.referrer }),
Meta({ name: 'creator', content: metadata.creator }),
Meta({ name: 'publisher', content: metadata.publisher }),
Meta({ name: 'robots', content: metadata.robots?.basic }),
Meta({ name: 'googlebot', content: metadata.robots?.googleBot }),
Meta({ name: 'abstract', content: metadata.abstract }),
...(metadata.archives
? metadata.archives.map((archive) => (
<link rel="archives" href={archive} />
))
: []),
...(metadata.assets
? metadata.assets.map((asset) => <link rel="assets" href={asset} />)
: []),
...(metadata.bookmarks
? metadata.bookmarks.map((bookmark) => (
<link rel="bookmarks" href={bookmark} />
))
: []),
...(metadata.pagination
? [
metadata.pagination.previous ? (
<link rel="prev" href={metadata.pagination.previous} />
) : null,
metadata.pagination.next ? (
<link rel="next" href={metadata.pagination.next} />
) : null,
]
: []),
Meta({ name: 'category', content: metadata.category }),
Meta({ name: 'classification', content: metadata.classification }),
...(metadata.other
? Object.entries(metadata.other).map(([name, content]) => {
if (Array.isArray(content)) {
return content.map((contentItem) =>
Meta({ name, content: contentItem })
)
} else {
return Meta({ name, content })
}
})
: []),
])
}
export function ItunesMeta({ itunes }: { itunes: ResolvedMetadata['itunes'] }) {
if (!itunes) return null
const { appId, appArgument } = itunes
let content = `app-id=${appId}`
if (appArgument) {
content += `, app-argument=${appArgument}`
}
return <meta name="apple-itunes-app" content={content} />
}
export function FacebookMeta({
facebook,
}: {
facebook: ResolvedMetadata['facebook']
}) {
if (!facebook) return null
const { appId, admins } = facebook
return MetaFilter([
appId ? <meta property="fb:app_id" content={appId} /> : null,
...(admins
? admins.map((admin) => <meta property="fb:admins" content={admin} />)
: []),
])
}
export function PinterestMeta({
pinterest,
}: {
pinterest: ResolvedMetadata['pinterest']
}) {
if (!pinterest || pinterest.richPin === undefined) return null
const { richPin } = pinterest
return <meta property="pinterest-rich-pin" content={richPin.toString()} />
}
const formatDetectionKeys = [
'telephone',
'date',
'address',
'email',
'url',
] as const
export function FormatDetectionMeta({
formatDetection,
}: {
formatDetection: ResolvedMetadata['formatDetection']
}) {
if (!formatDetection) return null
let content = ''
for (const key of formatDetectionKeys) {
if (formatDetection[key] === false) {
if (content) content += ', '
content += `${key}=no`
}
}
return content ? <meta name="format-detection" content={content} /> : null
}
export function AppleWebAppMeta({
appleWebApp,
}: {
appleWebApp: ResolvedMetadata['appleWebApp']
}) {
if (!appleWebApp) return null
const { capable, title, startupImage, statusBarStyle } = appleWebApp
return MetaFilter([
capable ? Meta({ name: 'mobile-web-app-capable', content: 'yes' }) : null,
Meta({ name: 'apple-mobile-web-app-title', content: title }),
startupImage
? startupImage.map((image) => (
<link
href={image.url}
media={image.media}
rel="apple-touch-startup-image"
/>
))
: null,
statusBarStyle
? Meta({
name: 'apple-mobile-web-app-status-bar-style',
content: statusBarStyle,
})
: null,
])
}
export function VerificationMeta({
verification,
}: {
verification: ResolvedMetadata['verification']
}) {
if (!verification) return null
return MetaFilter([
MultiMeta({
namePrefix: 'google-site-verification',
contents: verification.google,
}),
MultiMeta({ namePrefix: 'y_key', contents: verification.yahoo }),
MultiMeta({
namePrefix: 'yandex-verification',
contents: verification.yandex,
}),
MultiMeta({ namePrefix: 'me', contents: verification.me }),
...(verification.other
? Object.entries(verification.other).map(([key, value]) =>
MultiMeta({ namePrefix: key, contents: value })
)
: []),
])
}
import type { ResolvedMetadata } from '../types/metadata-interface'
import type { Icon, IconDescriptor } from '../types/metadata-types'
import { IconMark } from './icon-mark'
import { MetaFilter } from './meta'
function IconDescriptorLink({ icon }: { icon: IconDescriptor }) {
const { url, rel = 'icon', ...props } = icon
return <link rel={rel} href={url.toString()} {...props} />
}
function IconLink({ rel, icon }: { rel?: string; icon: Icon }) {
if (typeof icon === 'object' && !(icon instanceof URL)) {
if (!icon.rel && rel) icon.rel = rel
return IconDescriptorLink({ icon })
} else {
const href = icon.toString()
return <link rel={rel} href={href} />
}
}
export function IconsMetadata({ icons }: { icons: ResolvedMetadata['icons'] }) {
if (!icons) return null
const shortcutList = icons.shortcut
const iconList = icons.icon
const appleList = icons.apple
const otherList = icons.other
const hasIcon = Boolean(
shortcutList?.length ||
iconList?.length ||
appleList?.length ||
otherList?.length
)
if (!hasIcon) return null
return MetaFilter([
shortcutList
? shortcutList.map((icon) => IconLink({ rel: 'shortcut icon', icon }))
: null,
iconList ? iconList.map((icon) => IconLink({ rel: 'icon', icon })) : null,
appleList
? appleList.map((icon) => IconLink({ rel: 'apple-touch-icon', icon }))
: null,
otherList ? otherList.map((icon) => IconDescriptorLink({ icon })) : null,
hasIcon ? <IconMark /> : null,
])
}
import React from 'react'
import { nonNullable } from '../../non-nullable'
export function Meta({
name,
property,
content,
media,
}: {
name?: string
property?: string
media?: string
content: string | number | URL | null | undefined
}): React.ReactElement | null {
if (typeof content !== 'undefined' && content !== null && content !== '') {
return (
<meta
{...(name ? { name } : { property })}
{...(media ? { media } : undefined)}
content={typeof content === 'string' ? content : content.toString()}
/>
)
}
return null
}
export function MetaFilter<T extends {} | {}[]>(
items: (T | null)[]
): NonNullable<T>[] {
const acc: NonNullable<T>[] = []
for (const item of items) {
if (Array.isArray(item)) {
acc.push(...item.filter(nonNullable))
} else if (nonNullable(item)) {
acc.push(item)
}
}
return acc
}
type ExtendMetaContent = Record<
string,
undefined | string | URL | number | boolean | null | undefined
>
type MultiMetaContent =
| (ExtendMetaContent | string | URL | number)[]
| null
| undefined
function camelToSnake(camelCaseStr: string) {
return camelCaseStr.replace(/([A-Z])/g, function (match) {
return '_' + match.toLowerCase()
})
}
const aliasPropPrefixes = new Set([
'og:image',
'twitter:image',
'og:video',
'og:audio',
])
function getMetaKey(prefix: string, key: string) {
// Use `twitter:image` and `og:image` instead of `twitter:image:url` and `og:image:url`
// to be more compatible as it's a more common format.
// `og:video` & `og:audio` do not have a `:url` suffix alias
if (aliasPropPrefixes.has(prefix) && key === 'url') {
return prefix
}
if (prefix.startsWith('og:') || prefix.startsWith('twitter:')) {
key = camelToSnake(key)
}
return prefix + ':' + key
}
function ExtendMeta({
content,
namePrefix,
propertyPrefix,
}: {
content?: ExtendMetaContent
namePrefix?: string
propertyPrefix?: string
}) {
if (!content) return null
return MetaFilter(
Object.entries(content).map(([k, v]) => {
return typeof v === 'undefined'
? null
: Meta({
...(propertyPrefix && { property: getMetaKey(propertyPrefix, k) }),
...(namePrefix && { name: getMetaKey(namePrefix, k) }),
content: typeof v === 'string' ? v : v?.toString(),
})
})
)
}
export function MultiMeta({
propertyPrefix,
namePrefix,
contents,
}: {
propertyPrefix?: string
namePrefix?: string
contents?: MultiMetaContent | null
}) {
if (typeof contents === 'undefined' || contents === null) {
return null
}
return MetaFilter(
contents.map((content) => {
if (
typeof content === 'string' ||
typeof content === 'number' ||
content instanceof URL
) {
return Meta({
...(propertyPrefix
? { property: propertyPrefix }
: { name: namePrefix }),
content,
})
} else {
return ExtendMeta({
namePrefix,
propertyPrefix,
content,
})
}
})
)
}
import type { ResolvedMetadata } from '../types/metadata-interface'
import type { TwitterAppDescriptor } from '../types/twitter-types'
import { Meta, MetaFilter, MultiMeta } from './meta'
export function OpenGraphMetadata({
openGraph,
}: {
openGraph: ResolvedMetadata['openGraph']
}) {
if (!openGraph) {
return null
}
let typedOpenGraph
if ('type' in openGraph) {
const openGraphType = openGraph.type
switch (openGraphType) {
case 'website':
typedOpenGraph = [Meta({ property: 'og:type', content: 'website' })]
break
case 'article':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'article' }),
Meta({
property: 'article:published_time',
content: openGraph.publishedTime?.toString(),
}),
Meta({
property: 'article:modified_time',
content: openGraph.modifiedTime?.toString(),
}),
Meta({
property: 'article:expiration_time',
content: openGraph.expirationTime?.toString(),
}),
MultiMeta({
propertyPrefix: 'article:author',
contents: openGraph.authors,
}),
Meta({ property: 'article:section', content: openGraph.section }),
MultiMeta({
propertyPrefix: 'article:tag',
contents: openGraph.tags,
}),
]
break
case 'book':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'book' }),
Meta({ property: 'book:isbn', content: openGraph.isbn }),
Meta({
property: 'book:release_date',
content: openGraph.releaseDate,
}),
MultiMeta({
propertyPrefix: 'book:author',
contents: openGraph.authors,
}),
MultiMeta({ propertyPrefix: 'book:tag', contents: openGraph.tags }),
]
break
case 'profile':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'profile' }),
Meta({
property: 'profile:first_name',
content: openGraph.firstName,
}),
Meta({ property: 'profile:last_name', content: openGraph.lastName }),
Meta({ property: 'profile:username', content: openGraph.username }),
Meta({ property: 'profile:gender', content: openGraph.gender }),
]
break
case 'music.song':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'music.song' }),
Meta({
property: 'music:duration',
content: openGraph.duration?.toString(),
}),
MultiMeta({
propertyPrefix: 'music:album',
contents: openGraph.albums,
}),
MultiMeta({
propertyPrefix: 'music:musician',
contents: openGraph.musicians,
}),
]
break
case 'music.album':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'music.album' }),
MultiMeta({
propertyPrefix: 'music:song',
contents: openGraph.songs,
}),
MultiMeta({
propertyPrefix: 'music:musician',
contents: openGraph.musicians,
}),
Meta({
property: 'music:release_date',
content: openGraph.releaseDate,
}),
]
break
case 'music.playlist':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'music.playlist' }),
MultiMeta({
propertyPrefix: 'music:song',
contents: openGraph.songs,
}),
MultiMeta({
propertyPrefix: 'music:creator',
contents: openGraph.creators,
}),
]
break
case 'music.radio_station':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'music.radio_station' }),
MultiMeta({
propertyPrefix: 'music:creator',
contents: openGraph.creators,
}),
]
break
case 'video.movie':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'video.movie' }),
MultiMeta({
propertyPrefix: 'video:actor',
contents: openGraph.actors,
}),
MultiMeta({
propertyPrefix: 'video:director',
contents: openGraph.directors,
}),
MultiMeta({
propertyPrefix: 'video:writer',
contents: openGraph.writers,
}),
Meta({ property: 'video:duration', content: openGraph.duration }),
Meta({
property: 'video:release_date',
content: openGraph.releaseDate,
}),
MultiMeta({ propertyPrefix: 'video:tag', contents: openGraph.tags }),
]
break
case 'video.episode':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'video.episode' }),
MultiMeta({
propertyPrefix: 'video:actor',
contents: openGraph.actors,
}),
MultiMeta({
propertyPrefix: 'video:director',
contents: openGraph.directors,
}),
MultiMeta({
propertyPrefix: 'video:writer',
contents: openGraph.writers,
}),
Meta({ property: 'video:duration', content: openGraph.duration }),
Meta({
property: 'video:release_date',
content: openGraph.releaseDate,
}),
MultiMeta({ propertyPrefix: 'video:tag', contents: openGraph.tags }),
Meta({ property: 'video:series', content: openGraph.series }),
]
break
case 'video.tv_show':
typedOpenGraph = [
Meta({ property: 'og:type', content: 'video.tv_show' }),
]
break
case 'video.other':
typedOpenGraph = [Meta({ property: 'og:type', content: 'video.other' })]
break
default:
const _exhaustiveCheck: never = openGraphType
throw new Error(`Invalid OpenGraph type: ${_exhaustiveCheck}`)
}
}
return MetaFilter([
Meta({ property: 'og:determiner', content: openGraph.determiner }),
Meta({ property: 'og:title', content: openGraph.title?.absolute }),
Meta({ property: 'og:description', content: openGraph.description }),
Meta({ property: 'og:url', content: openGraph.url?.toString() }),
Meta({ property: 'og:site_name', content: openGraph.siteName }),
Meta({ property: 'og:locale', content: openGraph.locale }),
Meta({ property: 'og:country_name', content: openGraph.countryName }),
Meta({ property: 'og:ttl', content: openGraph.ttl?.toString() }),
MultiMeta({ propertyPrefix: 'og:image', contents: openGraph.images }),
MultiMeta({ propertyPrefix: 'og:video', contents: openGraph.videos }),
MultiMeta({ propertyPrefix: 'og:audio', contents: openGraph.audio }),
MultiMeta({ propertyPrefix: 'og:email', contents: openGraph.emails }),
MultiMeta({
propertyPrefix: 'og:phone_number',
contents: openGraph.phoneNumbers,
}),
MultiMeta({
propertyPrefix: 'og:fax_number',
contents: openGraph.faxNumbers,
}),
MultiMeta({
propertyPrefix: 'og:locale:alternate',
contents: openGraph.alternateLocale,
}),
...(typedOpenGraph ? typedOpenGraph : []),
])
}
function TwitterAppItem({
app,
type,
}: {
app: TwitterAppDescriptor
type: 'iphone' | 'ipad' | 'googleplay'
}) {
return [
Meta({ name: `twitter:app:name:${type}`, content: app.name }),
Meta({ name: `twitter:app:id:${type}`, content: app.id[type] }),
Meta({
name: `twitter:app:url:${type}`,
content: app.url?.[type]?.toString(),
}),
]
}
export function TwitterMetadata({
twitter,
}: {
twitter: ResolvedMetadata['twitter']
}) {
if (!twitter) return null
const { card } = twitter
return MetaFilter([
Meta({ name: 'twitter:card', content: card }),
Meta({ name: 'twitter:site', content: twitter.site }),
Meta({ name: 'twitter:site:id', content: twitter.siteId }),
Meta({ name: 'twitter:creator', content: twitter.creator }),
Meta({ name: 'twitter:creator:id', content: twitter.creatorId }),
Meta({ name: 'twitter:title', content: twitter.title?.absolute }),
Meta({ name: 'twitter:description', content: twitter.description }),
MultiMeta({ namePrefix: 'twitter:image', contents: twitter.images }),
...(card === 'player'
? twitter.players.flatMap((player) => [
Meta({
name: 'twitter:player',
content: player.playerUrl.toString(),
}),
Meta({
name: 'twitter:player:stream',
content: player.streamUrl.toString(),
}),
Meta({ name: 'twitter:player:width', content: player.width }),
Meta({ name: 'twitter:player:height', content: player.height }),
])
: []),
...(card === 'app'
? [
TwitterAppItem({ app: twitter.app, type: 'iphone' }),
TwitterAppItem({ app: twitter.app, type: 'ipad' }),
TwitterAppItem({ app: twitter.app, type: 'googleplay' }),
]
: []),
])
}
export function AppLinksMeta({
appLinks,
}: {
appLinks: ResolvedMetadata['appLinks']
}) {
if (!appLinks) return null
return MetaFilter([
MultiMeta({ propertyPrefix: 'al:ios', contents: appLinks.ios }),
MultiMeta({ propertyPrefix: 'al:iphone', contents: appLinks.iphone }),
MultiMeta({ propertyPrefix: 'al:ipad', contents: appLinks.ipad }),
MultiMeta({ propertyPrefix: 'al:android', contents: appLinks.android }),
MultiMeta({
propertyPrefix: 'al:windows_phone',
contents: appLinks.windows_phone,
}),
MultiMeta({ propertyPrefix: 'al:windows', contents: appLinks.windows }),
MultiMeta({
propertyPrefix: 'al:windows_universal',
contents: appLinks.windows_universal,
}),
MultiMeta({ propertyPrefix: 'al:web', contents: appLinks.web }),
])
}
import React, { Suspense, cache, cloneElement } from 'react'
import React, { Suspense, cache } from 'react'
import type { ParsedUrlQuery } from 'querystring'
import type { GetDynamicParamFromSegment } from '../../server/app-render/app-render'
import type { LoaderTree } from '../../server/lib/app-dir-module'
import type { SearchParams } from '../../server/request/search-params'
import {
AppleWebAppMeta,
FormatDetectionMeta,
ItunesMeta,
BasicMeta,
ViewportMeta,
VerificationMeta,
FacebookMeta,
PinterestMeta,
} from './generate/basic'
import { AlternatesMetadata } from './generate/alternate'
import {
OpenGraphMetadata,
TwitterMetadata,
AppLinksMeta,
} from './generate/opengraph'
import { IconsMetadata } from './generate/icons'
import {
type MetadataErrorType,
resolveMetadata,
resolveViewport,
} from './resolve-metadata'
import { MetaFilter } from './generate/meta'
import type {
ResolvedMetadata,
ResolvedViewport,
......@@ -43,6 +25,9 @@ import {
OutletBoundary,
} from '../framework/boundary-components'
import { getOrigin } from './generate/utils'
import { IconMark } from './generate/icon-mark'
// Use a promise to share the status of the metadata resolving,
// returning two components `MetadataTree` and `MetadataOutlet`
// `MetadataTree` is the one that will be rendered at first in the content sequence for metadata tags.
......@@ -312,15 +297,7 @@ async function renderMetadata(
workStore,
metadataContext
)
const elements: Array<React.ReactNode> =
createMetadataElements(resolvedMetadata)
return (
<>
{elements.map((el, index) => {
return cloneElement(el as React.ReactElement, { key: index })
})}
</>
)
return <>{createMetadataElements(resolvedMetadata)}</>
}
async function renderViewport(
......@@ -337,35 +314,1637 @@ async function renderViewport(
getDynamicParamFromSegment,
workStore
)
return <>{createViewportElements(resolvedViewport)}</>
}
const elements: Array<React.ReactNode> =
createViewportElements(resolvedViewport)
return (
<>
{elements.map((el, index) => {
return cloneElement(el as React.ReactElement, { key: index })
})}
</>
// ---------------------------------------------------------------------------
// Viewport tag rendering
// ---------------------------------------------------------------------------
function createViewportElements(
viewport: ResolvedViewport
): React.ReactElement[] {
const tags: React.ReactElement[] = []
let i = 0
tags.push(<meta key={i++} charSet="utf-8" />)
// Build viewport content string from layout properties
const viewportParts: string[] = []
if (viewport.width != null) {
viewportParts.push(`width=${viewport.width}`)
}
if (viewport.height != null) {
viewportParts.push(`height=${viewport.height}`)
}
if (viewport.initialScale != null) {
viewportParts.push(`initial-scale=${viewport.initialScale}`)
}
if (viewport.minimumScale != null) {
viewportParts.push(`minimum-scale=${viewport.minimumScale}`)
}
if (viewport.maximumScale != null) {
viewportParts.push(`maximum-scale=${viewport.maximumScale}`)
}
if (viewport.userScalable != null) {
viewportParts.push(`user-scalable=${viewport.userScalable ? 'yes' : 'no'}`)
}
if (viewport.viewportFit) {
viewportParts.push(`viewport-fit=${viewport.viewportFit}`)
}
if (viewport.interactiveWidget) {
viewportParts.push(`interactive-widget=${viewport.interactiveWidget}`)
}
if (viewportParts.length) {
tags.push(
<meta key={i++} name="viewport" content={viewportParts.join(', ')} />
)
}
}
if (viewport.themeColor) {
for (const themeColor of viewport.themeColor) {
if (themeColor.media) {
tags.push(
<meta
key={i++}
name="theme-color"
content={themeColor.color}
media={themeColor.media}
/>
)
} else {
tags.push(
<meta key={i++} name="theme-color" content={themeColor.color} />
)
}
}
}
if (viewport.colorScheme) {
tags.push(
<meta key={i++} name="color-scheme" content={viewport.colorScheme} />
)
}
function createMetadataElements(metadata: ResolvedMetadata) {
return MetaFilter([
BasicMeta({ metadata }),
AlternatesMetadata({ alternates: metadata.alternates }),
ItunesMeta({ itunes: metadata.itunes }),
FacebookMeta({ facebook: metadata.facebook }),
PinterestMeta({ pinterest: metadata.pinterest }),
FormatDetectionMeta({ formatDetection: metadata.formatDetection }),
VerificationMeta({ verification: metadata.verification }),
AppleWebAppMeta({ appleWebApp: metadata.appleWebApp }),
OpenGraphMetadata({ openGraph: metadata.openGraph }),
TwitterMetadata({ twitter: metadata.twitter }),
AppLinksMeta({ appLinks: metadata.appLinks }),
IconsMetadata({ icons: metadata.icons }),
])
return tags
}
function createViewportElements(viewport: ResolvedViewport) {
return MetaFilter([ViewportMeta({ viewport: viewport })])
// ---------------------------------------------------------------------------
// Metadata tag rendering
// ---------------------------------------------------------------------------
function createMetadataElements(
metadata: ResolvedMetadata
): React.ReactElement[] {
const tags: React.ReactElement[] = []
let i = 0
// --- Title ---
if (metadata.title !== null && metadata.title.absolute) {
tags.push(<title key={i++}>{metadata.title.absolute}</title>)
}
// --- Basic meta tags ---
if (metadata.description) {
tags.push(
<meta key={i++} name="description" content={metadata.description} />
)
}
if (metadata.applicationName) {
tags.push(
<meta
key={i++}
name="application-name"
content={metadata.applicationName}
/>
)
}
// --- Authors ---
if (metadata.authors) {
for (const author of metadata.authors) {
if (author.url) {
tags.push(<link key={i++} rel="author" href={author.url.toString()} />)
}
if (author.name) {
tags.push(<meta key={i++} name="author" content={author.name} />)
}
}
}
// --- Manifest ---
if (metadata.manifest) {
const manifestOrigin = getOrigin(metadata.manifest)
tags.push(
<link
key={i++}
rel="manifest"
href={metadata.manifest.toString()}
crossOrigin={
!manifestOrigin && process.env.VERCEL_ENV === 'preview'
? 'use-credentials'
: undefined
}
/>
)
}
if (metadata.generator) {
tags.push(<meta key={i++} name="generator" content={metadata.generator} />)
}
if (metadata.keywords && metadata.keywords.length) {
tags.push(
<meta key={i++} name="keywords" content={metadata.keywords.join(',')} />
)
}
if (metadata.referrer) {
tags.push(<meta key={i++} name="referrer" content={metadata.referrer} />)
}
if (metadata.creator) {
tags.push(<meta key={i++} name="creator" content={metadata.creator} />)
}
if (metadata.publisher) {
tags.push(<meta key={i++} name="publisher" content={metadata.publisher} />)
}
if (metadata.robots?.basic) {
tags.push(<meta key={i++} name="robots" content={metadata.robots.basic} />)
}
if (metadata.robots?.googleBot) {
tags.push(
<meta key={i++} name="googlebot" content={metadata.robots.googleBot} />
)
}
if (metadata.abstract) {
tags.push(<meta key={i++} name="abstract" content={metadata.abstract} />)
}
// --- Link rel arrays ---
if (metadata.archives) {
for (const archive of metadata.archives) {
tags.push(<link key={i++} rel="archives" href={archive} />)
}
}
if (metadata.assets) {
for (const asset of metadata.assets) {
tags.push(<link key={i++} rel="assets" href={asset} />)
}
}
if (metadata.bookmarks) {
for (const bookmark of metadata.bookmarks) {
tags.push(<link key={i++} rel="bookmarks" href={bookmark} />)
}
}
// --- Pagination ---
if (metadata.pagination) {
if (metadata.pagination.previous) {
tags.push(
<link key={i++} rel="prev" href={metadata.pagination.previous} />
)
}
if (metadata.pagination.next) {
tags.push(<link key={i++} rel="next" href={metadata.pagination.next} />)
}
}
if (metadata.category) {
tags.push(<meta key={i++} name="category" content={metadata.category} />)
}
if (metadata.classification) {
tags.push(
<meta key={i++} name="classification" content={metadata.classification} />
)
}
// --- Other (arbitrary name/value pairs) ---
if (metadata.other) {
for (const [name, content] of Object.entries(metadata.other)) {
if (Array.isArray(content)) {
for (const contentItem of content) {
if (contentItem != null && contentItem !== '') {
tags.push(
<meta key={i++} name={name} content={String(contentItem)} />
)
}
}
} else if (content != null && content !== '') {
tags.push(<meta key={i++} name={name} content={String(content)} />)
}
}
}
// --- Alternates ---
if (metadata.alternates) {
const { canonical, languages, media, types } = metadata.alternates
if (canonical && canonical.url) {
tags.push(
<link
key={i++}
rel="canonical"
href={canonical.url.toString()}
{...(canonical.title ? { title: canonical.title } : undefined)}
/>
)
}
if (languages) {
for (const [locale, descriptors] of Object.entries(languages)) {
if (descriptors) {
for (const descriptor of descriptors) {
if (descriptor.url) {
tags.push(
<link
key={i++}
rel="alternate"
hrefLang={locale}
href={descriptor.url.toString()}
{...(descriptor.title
? { title: descriptor.title }
: undefined)}
/>
)
}
}
}
}
}
if (media) {
for (const [mediaName, descriptors] of Object.entries(media)) {
if (descriptors) {
for (const descriptor of descriptors) {
if (descriptor.url) {
tags.push(
<link
key={i++}
rel="alternate"
media={mediaName}
href={descriptor.url.toString()}
{...(descriptor.title
? { title: descriptor.title }
: undefined)}
/>
)
}
}
}
}
}
if (types) {
for (const [type, descriptors] of Object.entries(types)) {
if (descriptors) {
for (const descriptor of descriptors) {
if (descriptor.url) {
tags.push(
<link
key={i++}
rel="alternate"
type={type}
href={descriptor.url.toString()}
{...(descriptor.title
? { title: descriptor.title }
: undefined)}
/>
)
}
}
}
}
}
}
// --- iTunes ---
if (metadata.itunes) {
const { appId, appArgument } = metadata.itunes
let itunesContent = `app-id=${appId}`
if (appArgument) {
itunesContent += `, app-argument=${appArgument}`
}
tags.push(
<meta key={i++} name="apple-itunes-app" content={itunesContent} />
)
}
// --- Facebook ---
if (metadata.facebook) {
if (metadata.facebook.appId) {
tags.push(
<meta
key={i++}
property="fb:app_id"
content={metadata.facebook.appId}
/>
)
}
if (metadata.facebook.admins) {
for (const admin of metadata.facebook.admins) {
tags.push(<meta key={i++} property="fb:admins" content={admin} />)
}
}
}
// --- Pinterest ---
if (metadata.pinterest && metadata.pinterest.richPin !== undefined) {
tags.push(
<meta
key={i++}
property="pinterest-rich-pin"
content={metadata.pinterest.richPin.toString()}
/>
)
}
// --- Format Detection ---
if (metadata.formatDetection) {
const formatDetectionKeys = [
'telephone',
'date',
'address',
'email',
'url',
] as const
let formatContent = ''
for (const key of formatDetectionKeys) {
if (metadata.formatDetection[key] === false) {
if (formatContent) formatContent += ', '
formatContent += `${key}=no`
}
}
if (formatContent) {
tags.push(
<meta key={i++} name="format-detection" content={formatContent} />
)
}
}
// --- Verification ---
if (metadata.verification) {
const verification = metadata.verification
if (verification.google) {
for (const value of verification.google) {
if (value != null && value !== '') {
tags.push(
<meta
key={i++}
name="google-site-verification"
content={String(value)}
/>
)
}
}
}
if (verification.yahoo) {
for (const value of verification.yahoo) {
if (value != null && value !== '') {
tags.push(<meta key={i++} name="y_key" content={String(value)} />)
}
}
}
if (verification.yandex) {
for (const value of verification.yandex) {
if (value != null && value !== '') {
tags.push(
<meta
key={i++}
name="yandex-verification"
content={String(value)}
/>
)
}
}
}
if (verification.me) {
for (const value of verification.me) {
if (value != null && value !== '') {
tags.push(<meta key={i++} name="me" content={String(value)} />)
}
}
}
if (verification.other) {
for (const [name, values] of Object.entries(verification.other)) {
for (const value of values) {
if (value != null && value !== '') {
tags.push(<meta key={i++} name={name} content={String(value)} />)
}
}
}
}
}
// --- Apple Web App ---
if (metadata.appleWebApp) {
const { capable, title, startupImage, statusBarStyle } =
metadata.appleWebApp
if (capable) {
tags.push(<meta key={i++} name="mobile-web-app-capable" content="yes" />)
}
if (title) {
tags.push(
<meta key={i++} name="apple-mobile-web-app-title" content={title} />
)
}
if (startupImage) {
for (const image of startupImage) {
if (image.media) {
tags.push(
<link
key={i++}
href={image.url}
media={image.media}
rel="apple-touch-startup-image"
/>
)
} else {
tags.push(
<link key={i++} href={image.url} rel="apple-touch-startup-image" />
)
}
}
}
if (statusBarStyle) {
tags.push(
<meta
key={i++}
name="apple-mobile-web-app-status-bar-style"
content={statusBarStyle}
/>
)
}
}
// --- Open Graph ---
if (metadata.openGraph) {
const og = metadata.openGraph
if (og.determiner) {
tags.push(
<meta key={i++} property="og:determiner" content={og.determiner} />
)
}
if (og.title?.absolute) {
tags.push(
<meta key={i++} property="og:title" content={og.title.absolute} />
)
}
if (og.description) {
tags.push(
<meta key={i++} property="og:description" content={og.description} />
)
}
if (og.url) {
tags.push(
<meta key={i++} property="og:url" content={og.url.toString()} />
)
}
if (og.siteName) {
tags.push(
<meta key={i++} property="og:site_name" content={og.siteName} />
)
}
if (og.locale) {
tags.push(<meta key={i++} property="og:locale" content={og.locale} />)
}
if (og.countryName) {
tags.push(
<meta key={i++} property="og:country_name" content={og.countryName} />
)
}
if (og.ttl != null) {
tags.push(
<meta key={i++} property="og:ttl" content={og.ttl.toString()} />
)
}
// OG images
if (og.images) {
for (const image of og.images) {
if (typeof image === 'string') {
tags.push(<meta key={i++} property="og:image" content={image} />)
} else {
if (image.url) {
tags.push(
<meta key={i++} property="og:image" content={String(image.url)} />
)
}
if (image.secureUrl) {
tags.push(
<meta
key={i++}
property="og:image:secure_url"
content={String(image.secureUrl)}
/>
)
}
if (image.type) {
tags.push(
<meta key={i++} property="og:image:type" content={image.type} />
)
}
if (image.width) {
tags.push(
<meta
key={i++}
property="og:image:width"
content={String(image.width)}
/>
)
}
if (image.height) {
tags.push(
<meta
key={i++}
property="og:image:height"
content={String(image.height)}
/>
)
}
if (image.alt) {
tags.push(
<meta key={i++} property="og:image:alt" content={image.alt} />
)
}
}
}
}
// OG videos
if (og.videos) {
for (const video of og.videos) {
if (typeof video === 'string') {
tags.push(<meta key={i++} property="og:video" content={video} />)
} else {
if (video.url) {
tags.push(
<meta key={i++} property="og:video" content={String(video.url)} />
)
}
if (video.secureUrl) {
tags.push(
<meta
key={i++}
property="og:video:secure_url"
content={String(video.secureUrl)}
/>
)
}
if (video.type) {
tags.push(
<meta key={i++} property="og:video:type" content={video.type} />
)
}
if (video.width) {
tags.push(
<meta
key={i++}
property="og:video:width"
content={String(video.width)}
/>
)
}
if (video.height) {
tags.push(
<meta
key={i++}
property="og:video:height"
content={String(video.height)}
/>
)
}
}
}
}
// OG audio
if (og.audio) {
for (const audio of og.audio) {
if (typeof audio === 'string') {
tags.push(<meta key={i++} property="og:audio" content={audio} />)
} else {
if (audio.url) {
tags.push(
<meta key={i++} property="og:audio" content={String(audio.url)} />
)
}
if (audio.secureUrl) {
tags.push(
<meta
key={i++}
property="og:audio:secure_url"
content={String(audio.secureUrl)}
/>
)
}
if (audio.type) {
tags.push(
<meta key={i++} property="og:audio:type" content={audio.type} />
)
}
}
}
}
// OG simple array properties
if (og.emails) {
for (const email of og.emails) {
tags.push(<meta key={i++} property="og:email" content={email} />)
}
}
if (og.phoneNumbers) {
for (const phone of og.phoneNumbers) {
tags.push(<meta key={i++} property="og:phone_number" content={phone} />)
}
}
if (og.faxNumbers) {
for (const fax of og.faxNumbers) {
tags.push(<meta key={i++} property="og:fax_number" content={fax} />)
}
}
if (og.alternateLocale) {
for (const locale of og.alternateLocale) {
tags.push(
<meta key={i++} property="og:locale:alternate" content={locale} />
)
}
}
// OG type-specific tags
if ('type' in og) {
const ogType = og.type
switch (ogType) {
case 'website':
tags.push(<meta key={i++} property="og:type" content="website" />)
break
case 'article':
tags.push(<meta key={i++} property="og:type" content="article" />)
if (og.publishedTime) {
tags.push(
<meta
key={i++}
property="article:published_time"
content={og.publishedTime.toString()}
/>
)
}
if (og.modifiedTime) {
tags.push(
<meta
key={i++}
property="article:modified_time"
content={og.modifiedTime.toString()}
/>
)
}
if (og.expirationTime) {
tags.push(
<meta
key={i++}
property="article:expiration_time"
content={og.expirationTime.toString()}
/>
)
}
if (og.authors) {
for (const author of og.authors) {
tags.push(
<meta
key={i++}
property="article:author"
content={String(author)}
/>
)
}
}
if (og.section) {
tags.push(
<meta key={i++} property="article:section" content={og.section} />
)
}
if (og.tags) {
for (const tag of og.tags) {
tags.push(<meta key={i++} property="article:tag" content={tag} />)
}
}
break
case 'book':
tags.push(<meta key={i++} property="og:type" content="book" />)
if (og.isbn) {
tags.push(<meta key={i++} property="book:isbn" content={og.isbn} />)
}
if (og.releaseDate) {
tags.push(
<meta
key={i++}
property="book:release_date"
content={og.releaseDate}
/>
)
}
if (og.authors) {
for (const author of og.authors) {
tags.push(
<meta
key={i++}
property="book:author"
content={String(author)}
/>
)
}
}
if (og.tags) {
for (const tag of og.tags) {
tags.push(<meta key={i++} property="book:tag" content={tag} />)
}
}
break
case 'profile':
tags.push(<meta key={i++} property="og:type" content="profile" />)
if (og.firstName) {
tags.push(
<meta
key={i++}
property="profile:first_name"
content={og.firstName}
/>
)
}
if (og.lastName) {
tags.push(
<meta
key={i++}
property="profile:last_name"
content={og.lastName}
/>
)
}
if (og.username) {
tags.push(
<meta
key={i++}
property="profile:username"
content={og.username}
/>
)
}
if (og.gender) {
tags.push(
<meta key={i++} property="profile:gender" content={og.gender} />
)
}
break
case 'music.song':
tags.push(<meta key={i++} property="og:type" content="music.song" />)
if (og.duration != null) {
tags.push(
<meta
key={i++}
property="music:duration"
content={og.duration.toString()}
/>
)
}
if (og.albums) {
for (const album of og.albums) {
if (typeof album === 'string') {
tags.push(
<meta key={i++} property="music:album" content={album} />
)
} else {
if (album.url) {
tags.push(
<meta
key={i++}
property="music:album"
content={String(album.url)}
/>
)
}
if (album.disc != null) {
tags.push(
<meta
key={i++}
property="music:album:disc"
content={String(album.disc)}
/>
)
}
if (album.track != null) {
tags.push(
<meta
key={i++}
property="music:album:track"
content={String(album.track)}
/>
)
}
}
}
}
if (og.musicians) {
for (const musician of og.musicians) {
tags.push(
<meta
key={i++}
property="music:musician"
content={String(musician)}
/>
)
}
}
break
case 'music.album':
tags.push(<meta key={i++} property="og:type" content="music.album" />)
if (og.songs) {
for (const song of og.songs) {
if (typeof song === 'string') {
tags.push(
<meta key={i++} property="music:song" content={song} />
)
} else {
if (song.url) {
tags.push(
<meta
key={i++}
property="music:song"
content={String(song.url)}
/>
)
}
if (song.disc != null) {
tags.push(
<meta
key={i++}
property="music:song:disc"
content={String(song.disc)}
/>
)
}
if (song.track != null) {
tags.push(
<meta
key={i++}
property="music:song:track"
content={String(song.track)}
/>
)
}
}
}
}
if (og.musicians) {
for (const musician of og.musicians) {
tags.push(
<meta
key={i++}
property="music:musician"
content={String(musician)}
/>
)
}
}
if (og.releaseDate) {
tags.push(
<meta
key={i++}
property="music:release_date"
content={og.releaseDate}
/>
)
}
break
case 'music.playlist':
tags.push(
<meta key={i++} property="og:type" content="music.playlist" />
)
if (og.songs) {
for (const song of og.songs) {
if (typeof song === 'string') {
tags.push(
<meta key={i++} property="music:song" content={song} />
)
} else {
if (song.url) {
tags.push(
<meta
key={i++}
property="music:song"
content={String(song.url)}
/>
)
}
if (song.disc != null) {
tags.push(
<meta
key={i++}
property="music:song:disc"
content={String(song.disc)}
/>
)
}
if (song.track != null) {
tags.push(
<meta
key={i++}
property="music:song:track"
content={String(song.track)}
/>
)
}
}
}
}
if (og.creators) {
for (const creator of og.creators) {
tags.push(
<meta
key={i++}
property="music:creator"
content={String(creator)}
/>
)
}
}
break
case 'music.radio_station':
tags.push(
<meta key={i++} property="og:type" content="music.radio_station" />
)
if (og.creators) {
for (const creator of og.creators) {
tags.push(
<meta
key={i++}
property="music:creator"
content={String(creator)}
/>
)
}
}
break
case 'video.movie':
tags.push(<meta key={i++} property="og:type" content="video.movie" />)
if (og.actors) {
for (const actor of og.actors) {
if (typeof actor === 'string') {
tags.push(
<meta key={i++} property="video:actor" content={actor} />
)
} else {
if (actor.url) {
tags.push(
<meta
key={i++}
property="video:actor"
content={String(actor.url)}
/>
)
}
if (actor.role) {
tags.push(
<meta
key={i++}
property="video:actor:role"
content={actor.role}
/>
)
}
}
}
}
if (og.directors) {
for (const director of og.directors) {
tags.push(
<meta
key={i++}
property="video:director"
content={String(director)}
/>
)
}
}
if (og.writers) {
for (const writer of og.writers) {
tags.push(
<meta
key={i++}
property="video:writer"
content={String(writer)}
/>
)
}
}
if (og.duration != null) {
tags.push(
<meta
key={i++}
property="video:duration"
content={String(og.duration)}
/>
)
}
if (og.releaseDate) {
tags.push(
<meta
key={i++}
property="video:release_date"
content={og.releaseDate}
/>
)
}
if (og.tags) {
for (const tag of og.tags) {
tags.push(<meta key={i++} property="video:tag" content={tag} />)
}
}
break
case 'video.episode':
tags.push(
<meta key={i++} property="og:type" content="video.episode" />
)
if (og.actors) {
for (const actor of og.actors) {
if (typeof actor === 'string') {
tags.push(
<meta key={i++} property="video:actor" content={actor} />
)
} else {
if (actor.url) {
tags.push(
<meta
key={i++}
property="video:actor"
content={String(actor.url)}
/>
)
}
if (actor.role) {
tags.push(
<meta
key={i++}
property="video:actor:role"
content={actor.role}
/>
)
}
}
}
}
if (og.directors) {
for (const director of og.directors) {
tags.push(
<meta
key={i++}
property="video:director"
content={String(director)}
/>
)
}
}
if (og.writers) {
for (const writer of og.writers) {
tags.push(
<meta
key={i++}
property="video:writer"
content={String(writer)}
/>
)
}
}
if (og.duration != null) {
tags.push(
<meta
key={i++}
property="video:duration"
content={String(og.duration)}
/>
)
}
if (og.releaseDate) {
tags.push(
<meta
key={i++}
property="video:release_date"
content={og.releaseDate}
/>
)
}
if (og.tags) {
for (const tag of og.tags) {
tags.push(<meta key={i++} property="video:tag" content={tag} />)
}
}
if (og.series) {
tags.push(
<meta
key={i++}
property="video:series"
content={String(og.series)}
/>
)
}
break
case 'video.tv_show':
tags.push(
<meta key={i++} property="og:type" content="video.tv_show" />
)
break
case 'video.other':
tags.push(<meta key={i++} property="og:type" content="video.other" />)
break
default:
const _exhaustiveCheck: never = ogType
throw new Error(`Invalid OpenGraph type: ${_exhaustiveCheck}`)
}
}
}
// --- Twitter ---
if (metadata.twitter) {
const tw = metadata.twitter
const { card } = tw
if (card) {
tags.push(<meta key={i++} name="twitter:card" content={card} />)
}
if (tw.site) {
tags.push(<meta key={i++} name="twitter:site" content={tw.site} />)
}
if (tw.siteId) {
tags.push(<meta key={i++} name="twitter:site:id" content={tw.siteId} />)
}
if (tw.creator) {
tags.push(<meta key={i++} name="twitter:creator" content={tw.creator} />)
}
if (tw.creatorId) {
tags.push(
<meta key={i++} name="twitter:creator:id" content={tw.creatorId} />
)
}
if (tw.title?.absolute) {
tags.push(
<meta key={i++} name="twitter:title" content={tw.title.absolute} />
)
}
if (tw.description) {
tags.push(
<meta key={i++} name="twitter:description" content={tw.description} />
)
}
// Twitter images
if (tw.images) {
for (const image of tw.images) {
if (typeof image === 'string') {
tags.push(<meta key={i++} name="twitter:image" content={image} />)
} else {
if (image.url) {
tags.push(
<meta
key={i++}
name="twitter:image"
content={String(image.url)}
/>
)
}
if (image.alt) {
tags.push(
<meta key={i++} name="twitter:image:alt" content={image.alt} />
)
}
if (image.secureUrl) {
tags.push(
<meta
key={i++}
name="twitter:image:secure_url"
content={String(image.secureUrl)}
/>
)
}
if (image.type) {
tags.push(
<meta key={i++} name="twitter:image:type" content={image.type} />
)
}
if (image.width) {
tags.push(
<meta
key={i++}
name="twitter:image:width"
content={String(image.width)}
/>
)
}
if (image.height) {
tags.push(
<meta
key={i++}
name="twitter:image:height"
content={String(image.height)}
/>
)
}
}
}
}
// Twitter player cards
if (card === 'player') {
for (const player of tw.players) {
tags.push(
<meta
key={i++}
name="twitter:player"
content={player.playerUrl.toString()}
/>
)
tags.push(
<meta
key={i++}
name="twitter:player:stream"
content={player.streamUrl.toString()}
/>
)
tags.push(
<meta
key={i++}
name="twitter:player:width"
content={String(player.width)}
/>
)
tags.push(
<meta
key={i++}
name="twitter:player:height"
content={String(player.height)}
/>
)
}
}
// Twitter app cards
if (card === 'app') {
const { app } = tw
for (const platform of ['iphone', 'ipad', 'googleplay'] as const) {
if (app.name) {
tags.push(
<meta
key={i++}
name={`twitter:app:name:${platform}`}
content={app.name}
/>
)
}
if (app.id[platform]) {
tags.push(
<meta
key={i++}
name={`twitter:app:id:${platform}`}
content={String(app.id[platform])}
/>
)
}
if (app.url?.[platform]) {
tags.push(
<meta
key={i++}
name={`twitter:app:url:${platform}`}
content={app.url[platform]!.toString()}
/>
)
}
}
}
}
// --- App Links ---
if (metadata.appLinks) {
const appLinks = metadata.appLinks
// iOS / iPhone / iPad (AppLinksApple: url, app_store_id, app_name)
if (appLinks.ios) {
for (const item of appLinks.ios) {
if (item.url) {
tags.push(
<meta key={i++} property="al:ios:url" content={String(item.url)} />
)
}
if (item.app_store_id) {
tags.push(
<meta
key={i++}
property="al:ios:app_store_id"
content={String(item.app_store_id)}
/>
)
}
if (item.app_name) {
tags.push(
<meta
key={i++}
property="al:ios:app_name"
content={item.app_name}
/>
)
}
}
}
if (appLinks.iphone) {
for (const item of appLinks.iphone) {
if (item.url) {
tags.push(
<meta
key={i++}
property="al:iphone:url"
content={String(item.url)}
/>
)
}
if (item.app_store_id) {
tags.push(
<meta
key={i++}
property="al:iphone:app_store_id"
content={String(item.app_store_id)}
/>
)
}
if (item.app_name) {
tags.push(
<meta
key={i++}
property="al:iphone:app_name"
content={item.app_name}
/>
)
}
}
}
if (appLinks.ipad) {
for (const item of appLinks.ipad) {
if (item.url) {
tags.push(
<meta key={i++} property="al:ipad:url" content={String(item.url)} />
)
}
if (item.app_store_id) {
tags.push(
<meta
key={i++}
property="al:ipad:app_store_id"
content={String(item.app_store_id)}
/>
)
}
if (item.app_name) {
tags.push(
<meta
key={i++}
property="al:ipad:app_name"
content={item.app_name}
/>
)
}
}
}
// Android (AppLinksAndroid: package, url, class, app_name)
if (appLinks.android) {
for (const item of appLinks.android) {
if (item.package) {
tags.push(
<meta
key={i++}
property="al:android:package"
content={item.package}
/>
)
}
if (item.url) {
tags.push(
<meta
key={i++}
property="al:android:url"
content={String(item.url)}
/>
)
}
if (item.class) {
tags.push(
<meta key={i++} property="al:android:class" content={item.class} />
)
}
if (item.app_name) {
tags.push(
<meta
key={i++}
property="al:android:app_name"
content={item.app_name}
/>
)
}
}
}
// Windows Phone (AppLinksWindows: url, app_id, app_name)
if (appLinks.windows_phone) {
for (const item of appLinks.windows_phone) {
if (item.url) {
tags.push(
<meta
key={i++}
property="al:windows_phone:url"
content={String(item.url)}
/>
)
}
if (item.app_id) {
tags.push(
<meta
key={i++}
property="al:windows_phone:app_id"
content={item.app_id}
/>
)
}
if (item.app_name) {
tags.push(
<meta
key={i++}
property="al:windows_phone:app_name"
content={item.app_name}
/>
)
}
}
}
// Windows (AppLinksWindows: url, app_id, app_name)
if (appLinks.windows) {
for (const item of appLinks.windows) {
if (item.url) {
tags.push(
<meta
key={i++}
property="al:windows:url"
content={String(item.url)}
/>
)
}
if (item.app_id) {
tags.push(
<meta
key={i++}
property="al:windows:app_id"
content={item.app_id}
/>
)
}
if (item.app_name) {
tags.push(
<meta
key={i++}
property="al:windows:app_name"
content={item.app_name}
/>
)
}
}
}
// Windows Universal (AppLinksWindows: url, app_id, app_name)
if (appLinks.windows_universal) {
for (const item of appLinks.windows_universal) {
if (item.url) {
tags.push(
<meta
key={i++}
property="al:windows_universal:url"
content={String(item.url)}
/>
)
}
if (item.app_id) {
tags.push(
<meta
key={i++}
property="al:windows_universal:app_id"
content={item.app_id}
/>
)
}
if (item.app_name) {
tags.push(
<meta
key={i++}
property="al:windows_universal:app_name"
content={item.app_name}
/>
)
}
}
}
// Web (AppLinksWeb: url, should_fallback)
if (appLinks.web) {
for (const item of appLinks.web) {
if (item.url) {
tags.push(
<meta key={i++} property="al:web:url" content={String(item.url)} />
)
}
if (item.should_fallback != null) {
tags.push(
<meta
key={i++}
property="al:web:should_fallback"
content={String(item.should_fallback)}
/>
)
}
}
}
}
// --- Icons ---
if (metadata.icons) {
const { shortcut, icon, apple, other } = metadata.icons
const hasIcon = Boolean(
shortcut?.length || icon?.length || apple?.length || other?.length
)
if (shortcut) {
for (const ic of shortcut) {
const { url, rel, ...props } = ic
tags.push(
<link
key={i++}
rel={rel || 'shortcut icon'}
href={url.toString()}
{...props}
/>
)
}
}
if (icon) {
for (const ic of icon) {
const { url, rel, ...props } = ic
tags.push(
<link
key={i++}
rel={rel || 'icon'}
href={url.toString()}
{...props}
/>
)
}
}
if (apple) {
for (const ic of apple) {
const { url, rel, ...props } = ic
tags.push(
<link
key={i++}
rel={rel || 'apple-touch-icon'}
href={url.toString()}
{...props}
/>
)
}
}
if (other) {
for (const ic of other) {
const { url, rel, ...props } = ic
tags.push(
<link
key={i++}
rel={rel || 'icon'}
href={url.toString()}
{...props}
/>
)
}
}
if (hasIcon) {
tags.push(<IconMark key={i++} />)
}
}
return tags
}
......@@ -283,12 +283,7 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/lib/memory/trace.js",
"/node_modules/next/dist/lib/metadata/constants.js",
"/node_modules/next/dist/lib/metadata/default-metadata.js",
"/node_modules/next/dist/lib/metadata/generate/alternate.js",
"/node_modules/next/dist/lib/metadata/generate/basic.js",
"/node_modules/next/dist/lib/metadata/generate/icon-mark.js",
"/node_modules/next/dist/lib/metadata/generate/icons.js",
"/node_modules/next/dist/lib/metadata/generate/meta.js",
"/node_modules/next/dist/lib/metadata/generate/opengraph.js",
"/node_modules/next/dist/lib/metadata/generate/utils.js",
"/node_modules/next/dist/lib/metadata/get-metadata-route.js",
"/node_modules/next/dist/lib/metadata/is-metadata-route.js",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment