Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct metadata url suffix (#69959) #70042

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/02-app/02-api-reference/04-functions/generate-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,18 @@ export const metadata = {
alt: 'My custom alt',
},
],
videos: [
{
url: 'https://nextjs.org/video.mp4', // Must be an absolute URL
width: 800,
height: 600,
},
],
audio: [
{
url: 'https://nextjs.org/audio.mp3', // Must be an absolute URL
},
],
locale: 'en_US',
type: 'website',
},
Expand All @@ -509,6 +521,10 @@ export const metadata = {
<meta property="og:image:width" content="1800" />
<meta property="og:image:height" content="1600" />
<meta property="og:image:alt" content="My custom alt" />
<meta property="og:video" content="https://nextjs.org/video.mp4" />
<meta property="og:video:width" content="800" />
<meta property="og:video:height" content="600" />
<meta property="og:audio" content="https://nextjs.org/audio.mp3" />
<meta property="og:type" content="website" />
```

Expand Down
11 changes: 9 additions & 2 deletions packages/next/src/lib/metadata/generate/meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ function camelToSnake(camelCaseStr: string) {
})
}

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
if ((prefix === 'og:image' || prefix === 'twitter:image') && key === '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:')) {
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/app-dir/metadata/app/opengraph/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export const metadata = {
alt: 'My custom alt',
},
],
videos: [
{
url: 'https://example.com/video.mp4',
width: 800,
height: 450,
},
],
audio: [
{
url: 'https://example.com/audio.mp3',
},
],
locale: 'en-US',
type: 'website',
},
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/app-dir/metadata/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ describe('app dir - metadata', () => {
'og:image:width': ['800', '1800'],
'og:image:height': ['600', '1600'],
'og:image:alt': 'My custom alt',
'og:video': 'https://example.com/video.mp4',
'og:video:width': '800',
'og:video:height': '450',
'og:audio': 'https://example.com/audio.mp3',
})

await matchMultiDom('meta', 'name', 'content', {
Expand Down
Loading