@@ -7,17 +7,22 @@ import { getOgImagePath, useOgImageRuntimeConfig } from '../../shared'
7
7
import { normaliseOptions } from './options'
8
8
9
9
export function nuxtContentPlugin ( nitroApp : NitroApp ) {
10
- const { isNuxtContentDocumentDriven, defaults } = useOgImageRuntimeConfig ( )
10
+ const { isNuxtContentDocumentDriven, strictNuxtContentPaths , defaults } = useOgImageRuntimeConfig ( )
11
11
nitroApp . hooks . hook ( 'content:file:afterParse' , async ( content : ParsedContent ) => {
12
12
if ( content . _draft || content . _extension !== 'md' || content . _partial || content . indexable === false || content . index === false )
13
13
return
14
14
15
15
let path = content . path
16
- if ( isNuxtContentDocumentDriven && content . path )
16
+ if ( isNuxtContentDocumentDriven && ! path )
17
17
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
+ }
18
23
// 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 : { } ) || { }
21
26
const optionsWithDefault = defu ( ogImageConfig , defaults )
22
27
// Note: we can't resolve the site URL here because we don't have access to the request
23
28
// the plugin nuxt-content-canonical-urls.ts fixes this
0 commit comments