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: useContentHead was not respecting og:image props #1461

Merged
merged 1 commit into from
Aug 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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