Unverified Commit fa51ff56 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

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

Backporting https://github.com/vercel/next.js/pull/69959Co-authored-by: 's avatarMaikel <maikel.van.dort@gmail.com>
parent 276ddf32
...@@ -490,6 +490,18 @@ export const metadata = { ...@@ -490,6 +490,18 @@ export const metadata = {
alt: 'My custom alt', 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', locale: 'en_US',
type: 'website', type: 'website',
}, },
...@@ -509,6 +521,10 @@ export const metadata = { ...@@ -509,6 +521,10 @@ export const metadata = {
<meta property="og:image:width" content="1800" /> <meta property="og:image:width" content="1800" />
<meta property="og:image:height" content="1600" /> <meta property="og:image:height" content="1600" />
<meta property="og:image:alt" content="My custom alt" /> <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" /> <meta property="og:type" content="website" />
``` ```
......
...@@ -53,10 +53,17 @@ function camelToSnake(camelCaseStr: string) { ...@@ -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) { function getMetaKey(prefix: string, key: string) {
// Use `twitter:image` and `og:image` instead of `twitter:image:url` and `og:image:url` // 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 // to be more compatible as it's a more common format.
if ((prefix === 'og:image' || prefix === 'twitter:image') && key === 'url') { // `og:video` & `og:audio` do not have a `:url` suffix alias
if (aliasPropPrefixes.has(prefix) && key === 'url') {
return prefix return prefix
} }
if (prefix.startsWith('og:') || prefix.startsWith('twitter:')) { if (prefix.startsWith('og:') || prefix.startsWith('twitter:')) {
......
...@@ -21,6 +21,18 @@ export const metadata = { ...@@ -21,6 +21,18 @@ export const metadata = {
alt: 'My custom alt', 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', locale: 'en-US',
type: 'website', type: 'website',
}, },
......
...@@ -482,6 +482,10 @@ describe('app dir - metadata', () => { ...@@ -482,6 +482,10 @@ describe('app dir - metadata', () => {
'og:image:width': ['800', '1800'], 'og:image:width': ['800', '1800'],
'og:image:height': ['600', '1600'], 'og:image:height': ['600', '1600'],
'og:image:alt': 'My custom alt', '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', { await matchMultiDom('meta', 'name', 'content', {
......
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