mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 19:41:02 +08:00
fix: get og image url correctly
This commit is contained in:
@@ -16,6 +16,7 @@ const blog = defineCollection({
|
|||||||
.refine(img => img.width >= 1200 && img.height >= 630, {
|
.refine(img => img.width >= 1200 && img.height >= 630, {
|
||||||
message: "OpenGraph image must be at least 1200 X 630 pixels!",
|
message: "OpenGraph image must be at least 1200 X 630 pixels!",
|
||||||
})
|
})
|
||||||
|
.or(z.string())
|
||||||
.optional(),
|
.optional(),
|
||||||
description: z.string(),
|
description: z.string(),
|
||||||
canonicalURL: z.string().optional(),
|
canonicalURL: z.string().optional(),
|
||||||
|
|||||||
@@ -18,10 +18,8 @@ const { title, author, description, ogImage, canonicalURL, pubDatetime, tags } =
|
|||||||
|
|
||||||
const { Content } = await post.render();
|
const { Content } = await post.render();
|
||||||
|
|
||||||
const ogUrl = new URL(
|
const ogImageUrl = typeof ogImage === "string" ? ogImage : ogImage?.src;
|
||||||
ogImage ? ogImage.src : `${post.slug}.png`,
|
const ogUrl = new URL(ogImageUrl ?? `${post.slug}.png`, Astro.url.origin).href;
|
||||||
Astro.url.origin
|
|
||||||
).href;
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout
|
<Layout
|
||||||
|
|||||||
Reference in New Issue
Block a user