From e3168c5d5ac03ca0b5f3f7996deb28e0f09e11a0 Mon Sep 17 00:00:00 2001 From: L4Ph <4ranci0ne@gmail.com> Date: Wed, 4 Jun 2025 22:53:19 +0900 Subject: [PATCH] Astro v5 with new API --- src/components/ArchivePanel.svelte | 2 +- src/components/PostCard.astro | 4 ++-- src/components/PostPage.astro | 2 +- src/components/misc/ImageWrapper.astro | 4 ++-- src/components/widget/TOC.astro | 2 +- src/{content/config.ts => content.config.ts} | 10 +++++++++- src/pages/posts/[...slug].astro | 9 +++++---- src/pages/rss.xml.ts | 2 +- src/utils/content-utils.ts | 4 ++-- src/utils/url-utils.ts | 4 ++-- 10 files changed, 26 insertions(+), 17 deletions(-) rename src/{content/config.ts => content.config.ts} (67%) diff --git a/src/components/ArchivePanel.svelte b/src/components/ArchivePanel.svelte index 17a9f490..3fb594c7 100644 --- a/src/components/ArchivePanel.svelte +++ b/src/components/ArchivePanel.svelte @@ -105,7 +105,7 @@ onMount(async () => { {#each group.posts as post} diff --git a/src/components/PostCard.astro b/src/components/PostCard.astro index 4546ce40..3935371b 100644 --- a/src/components/PostCard.astro +++ b/src/components/PostCard.astro @@ -1,6 +1,6 @@ --- import path from "node:path"; -import type { CollectionEntry } from "astro:content"; +import { type CollectionEntry, render } from "astro:content"; import { Icon } from "astro-icon/components"; import I18nKey from "../i18n/i18nKey"; import { i18n } from "../i18n/translation"; @@ -40,7 +40,7 @@ const hasCover = image !== undefined && image !== null && image !== ""; const coverWidth = "28%"; -const { remarkPluginFrontmatter } = await entry.render(); +const { remarkPluginFrontmatter } = await render(entry); ---
diff --git a/src/components/PostPage.astro b/src/components/PostPage.astro index 4e46ed46..a9700032 100644 --- a/src/components/PostPage.astro +++ b/src/components/PostPage.astro @@ -17,7 +17,7 @@ const interval = 50; category={entry.data.category} published={entry.data.published} updated={entry.data.updated} - url={getPostUrlBySlug(entry.slug)} + url={getPostUrlBySlug(entry.id)} image={entry.data.image} description={entry.data.description} draft={entry.data.draft} diff --git a/src/components/misc/ImageWrapper.astro b/src/components/misc/ImageWrapper.astro index cb591e35..be2a0727 100644 --- a/src/components/misc/ImageWrapper.astro +++ b/src/components/misc/ImageWrapper.astro @@ -38,8 +38,9 @@ if (isLocal) { console.error( `\n[ERROR] Image file not found: ${normalizedPath.replace("../../", "src/")}`, ); + } else { + img = await file(); } - img = await file(); } const imageClass = "w-full h-full object-cover"; @@ -50,4 +51,3 @@ const imageStyle = `object-position: ${position}`; {isLocal && img && {alt} {!isLocal && {alt}
- diff --git a/src/components/widget/TOC.astro b/src/components/widget/TOC.astro index 9a3977b9..e02042e8 100644 --- a/src/components/widget/TOC.astro +++ b/src/components/widget/TOC.astro @@ -34,7 +34,7 @@ const maxLevel = siteConfig.toc.depth; {isPostsRoute && {headings.filter((heading) => heading.depth < minDepth + maxLevel).map((heading) => -
({ - params: { slug: entry.slug }, + params: { slug: entry.id }, props: { entry }, })); } const { entry } = Astro.props; -const { Content, headings } = await entry.render(); +const { Content, headings } = await render(entry); -const { remarkPluginFrontmatter } = await entry.render(); +const { remarkPluginFrontmatter } = await render(entry); const jsonLd = { "@context": "https://schema.org", @@ -104,7 +105,7 @@ const jsonLd = { - {licenseConfig.enable && } + {licenseConfig.enable && }
diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index a3ae9c49..f0bc5631 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -22,7 +22,7 @@ export async function GET(context: APIContext) { title: post.data.title, pubDate: post.data.published, description: post.data.description || "", - link: `/posts/${post.slug}/`, + link: `/posts/${post.id}/`, content: sanitizeHtml(parser.render(content), { allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]), }), diff --git a/src/utils/content-utils.ts b/src/utils/content-utils.ts index a39a02f6..a71dd761 100644 --- a/src/utils/content-utils.ts +++ b/src/utils/content-utils.ts @@ -15,11 +15,11 @@ export async function getSortedPosts() { }); for (let i = 1; i < sorted.length; i++) { - sorted[i].data.nextSlug = sorted[i - 1].slug; + sorted[i].data.nextSlug = sorted[i - 1].id; sorted[i].data.nextTitle = sorted[i - 1].data.title; } for (let i = 0; i < sorted.length - 1; i++) { - sorted[i].data.prevSlug = sorted[i + 1].slug; + sorted[i].data.prevSlug = sorted[i + 1].id; sorted[i].data.prevTitle = sorted[i + 1].data.title; } diff --git a/src/utils/url-utils.ts b/src/utils/url-utils.ts index 956050bb..c055f339 100644 --- a/src/utils/url-utils.ts +++ b/src/utils/url-utils.ts @@ -12,8 +12,8 @@ function joinUrl(...parts: string[]): string { return joined.replace(/\/+/g, "/"); } -export function getPostUrlBySlug(slug: string): string { - return url(`/posts/${slug}/`); +export function getPostUrlBySlug(id: string): string { + return url(`/posts/${id}/`); } export function getTagUrl(tag: string): string {