Unverified Commit c5f1b459 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix metadata alternate and refactor twitter item (#45480)



x-ref: https://github.com/vercel/next.js/discussions/41745#discussioncomment-4827270

refactor twitter related items based on @gnoff 's feedback

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
parent a1c04b01
......@@ -13,16 +13,18 @@ export function AlternatesMetadata({
{alternates.canonical ? (
<link rel="canonical" href={alternates.canonical.toString()} />
) : null}
{Object.entries(alternates.languages).map(([locale, url]) =>
url ? (
<link
key={locale}
rel="alternate"
hrefLang={locale}
href={url.toString()}
/>
) : null
)}
{alternates.languages
? Object.entries(alternates.languages).map(([locale, url]) =>
url ? (
<link
key={locale}
rel="alternate"
hrefLang={locale}
href={url.toString()}
/>
) : null
)
: null}
{alternates.media
? Object.entries(alternates.media).map(([media, url]) =>
url ? (
......
......@@ -29,7 +29,7 @@ type MultiMetaContent =
| null
| undefined
export function ExtendMeta({
function ExtendMeta({
content,
namePrefix,
propertyPrefix,
......
import type { ResolvedMetadata } from '../types/metadata-interface'
import React from 'react'
import { ExtendMeta, Meta, MultiMeta } from './meta'
import { Meta, MultiMeta } from './meta'
import { TwitterAppDescriptor } from '../types/twitter-types'
export function OpenGraphMetadata({
......@@ -233,8 +233,11 @@ function TwitterAppItem({
return (
<>
<Meta name={`twitter:app:name:${type}`} content={app.name} />
<ExtendMeta namePrefix="twitter:app:id" content={app.id} />
<ExtendMeta namePrefix="twitter:app:url" content={app.url} />
<Meta name={`twitter:app:id:${type}`} content={app.id[type]} />
<Meta
name={`twitter:app:url:${type}`}
content={app.url?.[type]?.toString()}
/>
</>
)
}
......
......@@ -26,6 +26,7 @@ export const metadata = {
creator: 'shu',
publisher: 'vercel',
robots: 'index, follow',
alternates: {},
formatDetection: {
email: 'no',
address: 'no',
......
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