Commit 1b931ce7 authored by Jiwon Choi's avatar Jiwon Choi Committed by Zack Tanner

fix(next): `Metadata.openGraph` values not resolving basic values when `type` is set (#63620)

### What?

The string value of `Metadata.openGraph.emails` throws error:

```tsx
export const metadata = {
  openGraph: {
    type: 'article',
    emails: 'author@vercel.com',
  },
};
```

Error:

```sh
r.map is not a function
```

The type is:

```tsx
type OpenGraphMetadata = {
  // ...
  emails?: string | Array<string>
}
```

### Why?

Basic values such as `emails` and `phoneNumbers` were not included when
`ogType` was set while resolving the values.

### How?

Include basic values when resolving the metadata.

Fixes #63415
parent 6c31a2d4
...@@ -96,24 +96,20 @@ export function resolveImages( ...@@ -96,24 +96,20 @@ export function resolveImages(
return nonNullableImages return nonNullableImages
} }
const ogTypeToFields: Record<string, readonly string[]> = {
article: OgTypeFields.article,
book: OgTypeFields.article,
'music.song': OgTypeFields.song,
'music.album': OgTypeFields.song,
'music.playlist': OgTypeFields.playlist,
'music.radio_station': OgTypeFields.radio,
'video.movie': OgTypeFields.video,
'video.episode': OgTypeFields.video,
}
function getFieldsByOgType(ogType: OpenGraphType | undefined) { function getFieldsByOgType(ogType: OpenGraphType | undefined) {
switch (ogType) { if (!ogType || !(ogType in ogTypeToFields)) return OgTypeFields.basic
case 'article': return ogTypeToFields[ogType].concat(OgTypeFields.basic)
case 'book':
return OgTypeFields.article
case 'music.song':
case 'music.album':
return OgTypeFields.song
case 'music.playlist':
return OgTypeFields.playlist
case 'music.radio_station':
return OgTypeFields.radio
case 'video.movie':
case 'video.episode':
return OgTypeFields.video
default:
return OgTypeFields.basic
}
} }
function validateResolvedImageUrl( function validateResolvedImageUrl(
......
import type { Metadata } from 'next'
export default function Layout({ children }) { export default function Layout({ children }) {
return children return children
} }
...@@ -10,5 +12,8 @@ export const metadata = { ...@@ -10,5 +12,8 @@ export const metadata = {
publishedTime: '2023-01-01T00:00:00.000Z', publishedTime: '2023-01-01T00:00:00.000Z',
authors: ['author1', 'author2', 'author3'], authors: ['author1', 'author2', 'author3'],
images: new URL('https://example.com/og-image.jpg'), images: new URL('https://example.com/og-image.jpg'),
}, emails: 'author@vercel.com',
phoneNumbers: '1234567890',
faxNumbers: '1234567890',
} satisfies Metadata['openGraph'],
} }
...@@ -499,6 +499,9 @@ createNextDescribe( ...@@ -499,6 +499,9 @@ createNextDescribe(
'og:description': 'My custom description', 'og:description': 'My custom description',
'og:type': 'article', 'og:type': 'article',
'og:image': 'https://example.com/og-image.jpg', 'og:image': 'https://example.com/og-image.jpg',
'og:email': 'author@vercel.com',
'og:phone_number': '1234567890',
'og:fax_number': '1234567890',
'article:published_time': '2023-01-01T00:00:00.000Z', 'article:published_time': '2023-01-01T00:00:00.000Z',
'article:author': ['author1', 'author2', 'author3'], 'article:author': ['author1', 'author2', 'author3'],
}) })
......
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