Skip to content

Commit bcf241a

Browse files
authored
fix: useContentHead was not respecting og:image props (#1461)
1 parent bf35a81 commit bcf241a

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

playground/document-driven/content/0.index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
head.titleTemplate: '%s | TEST'
33
title: Hello World
44
description: Hello, here is a description
5+
image: 'https://picsum.photos/400/200'
56
---
67

78
# Home

src/runtime/composables/head.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const useContentHead = (
4444
head.meta.push({
4545
property: 'og:image',
4646
// @ts-ignore - We expect `head.image` from Nuxt configurations...
47-
content: head.image
47+
content: image
4848
})
4949
}
5050

@@ -70,7 +70,7 @@ export const useContentHead = (
7070
})
7171
} else if (image[key]) {
7272
head.meta.push({
73-
property: `og:${key}`,
73+
property: `og:image:${key}`,
7474
content: image[key]
7575
})
7676
}

test/document-driven.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ describe('fixtures:document-driven', async () => {
4747
expect(html).contains('with next link /no-surround')
4848
})
4949

50+
test('useContentHead(): og:image with string', async () => {
51+
const html = await $fetch('/fm-data')
52+
53+
expect(html).contains('<meta property="og:image" content="https://picsum.photos/400/200">')
54+
})
55+
56+
test('useContentHead(): og:image with object', async () => {
57+
const html = await $fetch('/og-image')
58+
59+
expect(html).contains('<meta property="og:image" content="https://picsum.photos/400/200">')
60+
expect(html).contains('<meta property="og:image:width" content="400">')
61+
expect(html).contains('<meta property="og:image:height" content="200">')
62+
})
63+
5064
test('404 page', async () => {
5165
try {
5266
await $fetch('/page-not-found')
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
score: 23.5
3+
image: 'https://picsum.photos/400/200'
34
---
45

5-
# FM Data
6+
# FM Data
File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
image.src: 'https://picsum.photos/400/200'
3+
image.width: 400
4+
image.height: 200
5+
---
6+
7+
# OG Image

0 commit comments

Comments
 (0)