Skip to content

Commit a988a74

Browse files
committedDec 15, 2024·
fix: prerender using crawled query params
1 parent 091c685 commit a988a74

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed
 

Diff for: ‎src/runtime/app/composables/defineOgImage.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ export function defineOgImage(_options: DefineOgImageInput = {}) {
5454
createOgImageMeta(null, options, resolvedOptions, nuxtApp.ssrContext!)
5555
}
5656
else {
57-
const path = getOgImagePath(basePath, resolvedOptions)
58-
if (import.meta.prerender)
59-
appendHeader(useRequestEvent(), 'x-nitro-prerender', path)
57+
const path = getOgImagePath(basePath, defu(resolvedOptions, { _query: options._query }))
58+
if (import.meta.prerender) {
59+
appendHeader(useRequestEvent(nuxtApp)!, 'x-nitro-prerender', path)
60+
}
6061
createOgImageMeta(path, options, resolvedOptions, nuxtApp.ssrContext!)
6162
}
6263
}

Diff for: ‎src/runtime/server/og-image/context.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import { logger } from '../util/logger'
2525
import { normaliseOptions } from '../util/options'
2626
import { useChromiumRenderer, useSatoriRenderer } from './instances'
2727

28-
export function resolvePathCacheKey(e: H3Event, path?: string) {
28+
export function resolvePathCacheKey(e: H3Event, path: string) {
2929
const siteConfig = e.context.siteConfig.get()
30-
const basePath = withoutTrailingSlash(withoutLeadingSlash(normalizeKey(path || e.path)))
30+
const basePath = withoutTrailingSlash(withoutLeadingSlash(normalizeKey(path)))
3131
return [
3232
(!basePath || basePath === '/') ? 'index' : basePath,
3333
hash([

Diff for: ‎src/runtime/shared.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Head } from '@unhead/schema'
22
import type { OgImageOptions, OgImageRuntimeConfig } from './types'
33
import { useRuntimeConfig } from '#imports'
44
import { defu } from 'defu'
5-
import { joinURL } from 'ufo'
5+
import { joinURL, withQuery } from 'ufo'
66
import { getExtension } from './pure'
77

88
// must work in both Nuxt an
@@ -39,7 +39,11 @@ export function generateMeta(url: string, resolvedOptions: OgImageOptions) {
3939
export function getOgImagePath(pagePath: string, _options?: Partial<OgImageOptions>) {
4040
const baseURL = useRuntimeConfig().app.baseURL
4141
const options = defu(_options, useOgImageRuntimeConfig().defaults)
42-
return joinURL('/', baseURL, `__og-image__/${import.meta.prerender ? 'static' : 'image'}`, pagePath, `og.${options.extension}`)
42+
const path = joinURL('/', baseURL, `__og-image__/${import.meta.prerender ? 'static' : 'image'}`, pagePath, `og.${options.extension}`)
43+
if (Object.keys(options._query || {}).length) {
44+
return withQuery(path, options._query)
45+
}
46+
return path
4347
}
4448

4549
export function useOgImageRuntimeConfig() {

0 commit comments

Comments
 (0)
Please sign in to comment.