Skip to content

Commit

Permalink
refactor: minor types clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Jan 27, 2024
1 parent 119918e commit 5fde697
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { setupPrerenderHandler } from './build/prerender'
import { setupBuildHandler } from './build/build'
import { ensureChromium } from './build/ensureChromium'
import { normaliseFontInput } from './runtime/utils.pure'
import { isUndefinedOrTruthy } from './util'

export interface ModuleOptions {
/**
Expand Down Expand Up @@ -297,19 +298,19 @@ export default defineNuxtModule<ModuleOptions>({
addServerHandler({
lazy: true,
route: '/__og-image__/font/**',
handler: resolve('./runtime/server/routes/__og-image__/font-[name]-[weight].[extension]'),
handler: resolve('./runtime/nitro/routes/__og-image__/font-[name]-[weight].[extension]'),
})
if (config.debug || nuxt.options.dev) {
addServerHandler({
lazy: true,
route: '/__og-image__/debug.json',
handler: resolve('./runtime/server/routes/__og-image__/debug.json'),
handler: resolve('./runtime/nitro/routes/__og-image__/debug.json'),
})
}
addServerHandler({
lazy: true,
route: '/__og-image__/image/**',
handler: resolve('./runtime/server/routes/__og-image__/image'),
handler: resolve('./runtime/nitro/routes/__og-image__/image'),
})

nuxt.options.optimization.treeShake.composables.client['nuxt-og-image'] = []
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/composables/defineOgImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export function defineOgImage(_options: DefineOgImageInput = {}) {
const resolvedOptions = normaliseOptions(defu(separateProps(_options), separateProps(routeRules), defaults) as OgImageOptions)
// allow overriding using a prebuild config
if (_options.url) {
createOgImageMeta(null, options, resolvedOptions, nuxtApp.ssrContext)
createOgImageMeta(null, options, resolvedOptions, nuxtApp.ssrContext!)
}
else {
const path = getOgImagePath(basePath, resolvedOptions)
if (import.meta.prerender)
appendHeader(useRequestEvent(), 'x-nitro-prerender', path)
createOgImageMeta(path, options, resolvedOptions, nuxtApp.ssrContext)
createOgImageMeta(path, options, resolvedOptions, nuxtApp.ssrContext!)
}
}
5 changes: 2 additions & 3 deletions src/runtime/nuxt/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { withQuery } from 'ufo'
import { getExtension, separateProps } from '../utils'
import type { DefineOgImageInput, OgImageOptions, OgImagePrebuilt } from '../types'
import { unref, useServerHead } from '#imports'

// @ts-expect-error untyped
import { componentNames } from '#build/nuxt-og-image/components.mjs'
import type { NuxtSSRContext } from '#app'

export function createOgImageMeta(src: string | null, input: OgImageOptions | OgImagePrebuilt, resolvedOptions: OgImageOptions, ssrContext: Record<string, any>) {
export function createOgImageMeta(src: string | null, input: OgImageOptions | OgImagePrebuilt, resolvedOptions: OgImageOptions, ssrContext: NuxtSSRContext) {
const _input = separateProps(defu(input, ssrContext._ogImagePayload))
let url = src || input.url || resolvedOptions.url
if (!url)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface ScreenshotOptions {
delay?: number
}

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

export type DefineOgImageInput = OgImageOptions | OgImagePrebuilt | false

Expand Down
1 change: 1 addition & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isUndefinedOrTruthy = (v?: any) => typeof v === 'undefined' || v !== false

0 comments on commit 5fde697

Please sign in to comment.