From 7f3edbdecdce597d15e562e7d497d69af505d550 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Wed, 20 Sep 2023 15:33:51 +0530 Subject: [PATCH] fix: get og image url correctly --- src/content/config.ts | 1 + src/layouts/PostDetails.astro | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/content/config.ts b/src/content/config.ts index 9f2754f..fdc0c2d 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -16,6 +16,7 @@ const blog = defineCollection({ .refine(img => img.width >= 1200 && img.height >= 630, { message: "OpenGraph image must be at least 1200 X 630 pixels!", }) + .or(z.string()) .optional(), description: z.string(), canonicalURL: z.string().optional(), diff --git a/src/layouts/PostDetails.astro b/src/layouts/PostDetails.astro index 9047ef7..6862b16 100644 --- a/src/layouts/PostDetails.astro +++ b/src/layouts/PostDetails.astro @@ -18,10 +18,8 @@ const { title, author, description, ogImage, canonicalURL, pubDatetime, tags } = const { Content } = await post.render(); -const ogUrl = new URL( - ogImage ? ogImage.src : `${post.slug}.png`, - Astro.url.origin -).href; +const ogImageUrl = typeof ogImage === "string" ? ogImage : ogImage?.src; +const ogUrl = new URL(ogImageUrl ?? `${post.slug}.png`, Astro.url.origin).href; ---