Skip to content

Commit

Permalink
fix: get og image url correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqmanuja authored and satnaing committed Sep 25, 2023
1 parent b03b722 commit 7f3edbd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 2 additions & 4 deletions src/layouts/PostDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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;
---

<Layout
Expand Down

0 comments on commit 7f3edbd

Please sign in to comment.