Skip to content

Commit

Permalink
Use og:image instead of og:image:url (#46570)
Browse files Browse the repository at this point in the history
x-ref: #46545

In the open graph protocol spec, `og:image` and `og:image:url` are identical. But some platform might don't have full support for it.

We change it back to render `og:image` as it's the most common and compatible format, also easy to align with the code docs
  • Loading branch information
huozhi authored Feb 28, 2023
1 parent 89a9bd9 commit 4b705a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/next/src/lib/metadata/generate/meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ function ExtendMeta({
<Meta
key={keyPrefix + ':' + k + '_' + index}
{...(propertyPrefix
? { property: propertyPrefix + ':' + k }
? // Use `og:image` instead of `og:image:url` to be more compatible as it's a more common format
{
property:
propertyPrefix === 'og:image' && k === 'url'
? 'og:image'
: propertyPrefix + ':' + k,
}
: { name: namePrefix + ':' + k })}
content={typeof v === 'string' ? v : v?.toString()}
/>
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/app-dir/metadata/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ createNextDescribe(
)
await checkMetaPropertyContentPair(browser, 'og:locale', 'en-US')
await checkMetaPropertyContentPair(browser, 'og:type', 'website')
await checkMetaPropertyContentPair(browser, 'og:image:url', [
await checkMetaPropertyContentPair(browser, 'og:image', [
'https://example.com/image.png',
'https://example.com/image2.png',
])
Expand Down Expand Up @@ -464,7 +464,7 @@ createNextDescribe(

it('should pick up opengraph-image and twitter-image as static metadata files', async () => {
const $ = await next.render$('/opengraph/static')
expect($('[property="og:image:url"]').attr('content')).toMatch(
expect($('[property="og:image"]').attr('content')).toMatch(
/https:\/\/example.com\/_next\/static\/media\/metadata\/opengraph-image.\w+.png/
)
expect($('[property="og:image:type"]').attr('content')).toBe(
Expand Down

0 comments on commit 4b705a5

Please sign in to comment.