Skip to content

Commit

Permalink
fix(defineOgImage): config usage
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Dec 15, 2022
1 parent 9ff952c commit d250a9e
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/runtime/composables/defineOgImage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useServerHead } from '@vueuse/head'
import { useRouter } from '#imports'

export const HtmlRendererRoute = '__og_image'
export const RuntimeImageSuffix = 'og-image.png'
Expand All @@ -7,14 +8,14 @@ export const MetaOgImageContentPlaceholder = '__NUXT_OG_IMAGE_PLACEHOLDER__'
export const LinkPrerenderId = 'nuxt-og-image-screenshot-path'

export interface OgImagePayload {
runtime: boolean
title: string
description: string
component: string
runtime?: boolean
title?: string
description?: string
component?: string
[key: string]: any
}

export function defineOgImage(options: OgImagePayload) {
export function defineOgImage(options: OgImagePayload = {}) {
if (process.server) {
const router = useRouter()
useServerHead({
Expand All @@ -24,13 +25,15 @@ export function defineOgImage(options: OgImagePayload) {
content: () => options.runtime ? `${router.currentRoute.value.path}/${RuntimeImageSuffix}` : MetaOgImageContentPlaceholder,
},
],
link: [
{
id: LinkPrerenderId,
rel: 'prerender',
href: `${router.currentRoute.value.path}/${HtmlRendererRoute}`,
},
],
link: options.component
? [
{
id: LinkPrerenderId,
rel: 'prerender',
href: `${router.currentRoute.value.path}/${HtmlRendererRoute}`,
},
]
: [],
script: [
{
id: PayloadScriptId,
Expand Down

0 comments on commit d250a9e

Please sign in to comment.