Skip to content

Commit 10c21e5

Browse files
committedNov 23, 2024
fix: default enabled content og images when strictNuxtContentPaths
1 parent d8327a9 commit 10c21e5

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed
 

Diff for: ‎src/module.ts

+1
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ declare module '#og-image/unocss-config' {
594594
hasNuxtIcon: hasNuxtModule('nuxt-icon') || hasNuxtModule('@nuxt/icon'),
595595
colorPreference,
596596

597+
strictNuxtContentPaths: config.strictNuxtContentPaths,
597598
// @ts-expect-error runtime type
598599
isNuxtContentDocumentDriven: config.strictNuxtContentPaths || !!nuxt.options.content?.documentDriven,
599600
}

Diff for: ‎src/runtime/server/util/plugins.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ import { getOgImagePath, useOgImageRuntimeConfig } from '../../shared'
77
import { normaliseOptions } from './options'
88

99
export function nuxtContentPlugin(nitroApp: NitroApp) {
10-
const { isNuxtContentDocumentDriven, defaults } = useOgImageRuntimeConfig()
10+
const { isNuxtContentDocumentDriven, strictNuxtContentPaths, defaults } = useOgImageRuntimeConfig()
1111
nitroApp.hooks.hook('content:file:afterParse', async (content: ParsedContent) => {
1212
if (content._draft || content._extension !== 'md' || content._partial || content.indexable === false || content.index === false)
1313
return
1414

1515
let path = content.path
16-
if (isNuxtContentDocumentDriven && content.path)
16+
if (isNuxtContentDocumentDriven && !path)
1717
path = content._path
18+
let shouldRenderOgImage = !!content.ogImage
19+
// if an effort was made to get the og image working for content we always render it
20+
if (typeof content.ogImage === 'undefined' && (strictNuxtContentPaths || typeof content.path !== 'undefined')) {
21+
shouldRenderOgImage = true
22+
}
1823
// convert ogImage to head tags
19-
if (path && content.ogImage) {
20-
const ogImageConfig = typeof content.ogImage === 'object' ? content.ogImage : {}
24+
if (path && shouldRenderOgImage) {
25+
const ogImageConfig = (typeof content.ogImage === 'object' ? content.ogImage : {}) || {}
2126
const optionsWithDefault = defu(ogImageConfig, defaults)
2227
// Note: we can't resolve the site URL here because we don't have access to the request
2328
// the plugin nuxt-content-canonical-urls.ts fixes this

Diff for: ‎src/runtime/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface OgImageRuntimeConfig {
3737
colorPreference: 'light' | 'dark'
3838

3939
isNuxtContentDocumentDriven: boolean
40+
strictNuxtContentPaths: boolean
4041
zeroRuntime: boolean
4142
}
4243

0 commit comments

Comments
 (0)
Please sign in to comment.