Skip to content

Commit

Permalink
fix: useContentHead was not respecting og:image props (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Aug 17, 2022
1 parent bf35a81 commit bcf241a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions playground/document-driven/content/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
head.titleTemplate: '%s | TEST'
title: Hello World
description: Hello, here is a description
image: 'https://picsum.photos/400/200'
---

# Home
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/composables/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const useContentHead = (
head.meta.push({
property: 'og:image',
// @ts-ignore - We expect `head.image` from Nuxt configurations...
content: head.image
content: image
})
}

Expand All @@ -70,7 +70,7 @@ export const useContentHead = (
})
} else if (image[key]) {
head.meta.push({
property: `og:${key}`,
property: `og:image:${key}`,
content: image[key]
})
}
Expand Down
14 changes: 14 additions & 0 deletions test/document-driven.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ describe('fixtures:document-driven', async () => {
expect(html).contains('with next link /no-surround')
})

test('useContentHead(): og:image with string', async () => {
const html = await $fetch('/fm-data')

expect(html).contains('<meta property="og:image" content="https://picsum.photos/400/200">')
})

test('useContentHead(): og:image with object', async () => {
const html = await $fetch('/og-image')

expect(html).contains('<meta property="og:image" content="https://picsum.photos/400/200">')
expect(html).contains('<meta property="og:image:width" content="400">')
expect(html).contains('<meta property="og:image:height" content="200">')
})

test('404 page', async () => {
try {
await $fetch('/page-not-found')
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/document-driven/content/3.fm-data.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
score: 23.5
image: 'https://picsum.photos/400/200'
---

# FM Data
# FM Data
7 changes: 7 additions & 0 deletions test/fixtures/document-driven/content/5.og-image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
image.src: 'https://picsum.photos/400/200'
image.width: 400
image.height: 200
---

# OG Image

0 comments on commit bcf241a

Please sign in to comment.