Skip to content

Commit 5fde697

Browse files
committed
refactor: minor types clean up
1 parent 119918e commit 5fde697

File tree

8 files changed

+10
-9
lines changed

8 files changed

+10
-9
lines changed

src/module.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { setupPrerenderHandler } from './build/prerender'
4545
import { setupBuildHandler } from './build/build'
4646
import { ensureChromium } from './build/ensureChromium'
4747
import { normaliseFontInput } from './runtime/utils.pure'
48+
import { isUndefinedOrTruthy } from './util'
4849

4950
export interface ModuleOptions {
5051
/**
@@ -297,19 +298,19 @@ export default defineNuxtModule<ModuleOptions>({
297298
addServerHandler({
298299
lazy: true,
299300
route: '/__og-image__/font/**',
300-
handler: resolve('./runtime/server/routes/__og-image__/font-[name]-[weight].[extension]'),
301+
handler: resolve('./runtime/nitro/routes/__og-image__/font-[name]-[weight].[extension]'),
301302
})
302303
if (config.debug || nuxt.options.dev) {
303304
addServerHandler({
304305
lazy: true,
305306
route: '/__og-image__/debug.json',
306-
handler: resolve('./runtime/server/routes/__og-image__/debug.json'),
307+
handler: resolve('./runtime/nitro/routes/__og-image__/debug.json'),
307308
})
308309
}
309310
addServerHandler({
310311
lazy: true,
311312
route: '/__og-image__/image/**',
312-
handler: resolve('./runtime/server/routes/__og-image__/image'),
313+
handler: resolve('./runtime/nitro/routes/__og-image__/image'),
313314
})
314315

315316
nuxt.options.optimization.treeShake.composables.client['nuxt-og-image'] = []

src/runtime/composables/defineOgImage.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ export function defineOgImage(_options: DefineOgImageInput = {}) {
3939
const resolvedOptions = normaliseOptions(defu(separateProps(_options), separateProps(routeRules), defaults) as OgImageOptions)
4040
// allow overriding using a prebuild config
4141
if (_options.url) {
42-
createOgImageMeta(null, options, resolvedOptions, nuxtApp.ssrContext)
42+
createOgImageMeta(null, options, resolvedOptions, nuxtApp.ssrContext!)
4343
}
4444
else {
4545
const path = getOgImagePath(basePath, resolvedOptions)
4646
if (import.meta.prerender)
4747
appendHeader(useRequestEvent(), 'x-nitro-prerender', path)
48-
createOgImageMeta(path, options, resolvedOptions, nuxtApp.ssrContext)
48+
createOgImageMeta(path, options, resolvedOptions, nuxtApp.ssrContext!)
4949
}
5050
}

src/runtime/nuxt/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { withQuery } from 'ufo'
44
import { getExtension, separateProps } from '../utils'
55
import type { DefineOgImageInput, OgImageOptions, OgImagePrebuilt } from '../types'
66
import { unref, useServerHead } from '#imports'
7-
8-
// @ts-expect-error untyped
97
import { componentNames } from '#build/nuxt-og-image/components.mjs'
8+
import type { NuxtSSRContext } from '#app'
109

11-
export function createOgImageMeta(src: string | null, input: OgImageOptions | OgImagePrebuilt, resolvedOptions: OgImageOptions, ssrContext: Record<string, any>) {
10+
export function createOgImageMeta(src: string | null, input: OgImageOptions | OgImagePrebuilt, resolvedOptions: OgImageOptions, ssrContext: NuxtSSRContext) {
1211
const _input = separateProps(defu(input, ssrContext._ogImagePayload))
1312
let url = src || input.url || resolvedOptions.url
1413
if (!url)

src/runtime/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export interface ScreenshotOptions {
6767
delay?: number
6868
}
6969

70-
export type OgImagePrebuilt = { url: string } & Pick<OgImageOptions, 'width' | 'height' | 'alt'>
70+
export type OgImagePrebuilt = { url: string } & Pick<OgImageOptions, 'width' | 'height' | 'alt' | '_query'>
7171

7272
export type DefineOgImageInput = OgImageOptions | OgImagePrebuilt | false
7373

src/util.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const isUndefinedOrTruthy = (v?: any) => typeof v === 'undefined' || v !== false

0 commit comments

Comments
 (0)