feat(upgrade): 迁移到 Astro V6

This commit is contained in:
Ad-closeNN
2026-04-19 22:12:00 +08:00
parent a96c270bfe
commit 27a6f94f64
11 changed files with 2940 additions and 3437 deletions
+8 -5
View File
@@ -1,5 +1,6 @@
---
import path from "node:path";
import { render, type CollectionEntry } from "astro:content";
import License from "@components/misc/License.astro";
import Markdown from "@components/misc/Markdown.astro";
import I18nKey from "@i18n/i18nKey";
@@ -17,15 +18,17 @@ import { formatDateToYYYYMMDD } from "../../utils/date-utils";
export async function getStaticPaths() {
const blogEntries = await getSortedPosts();
return blogEntries.map((entry) => ({
params: { slug: entry.slug },
params: { slug: entry.id },
props: { entry },
}));
}
const { entry } = Astro.props;
const { Content, headings } = await entry.render();
interface Props {
entry: CollectionEntry<"posts">;
}
const { remarkPluginFrontmatter } = await entry.render();
const { entry }: Props = Astro.props;
const { Content, headings, remarkPluginFrontmatter } = await render(entry);
const jsonLd = {
"@context": "https://schema.org",
@@ -134,7 +137,7 @@ const customcover = entry.data.customcover;
<Content />
</Markdown>
{licenseConfig.enable && <License title={entry.data.title} slug={entry.slug} pubDate={entry.data.published} class="mb-6 rounded-xl license-container onload-animation"></License>}
{licenseConfig.enable && <License title={entry.data.title} slug={entry.id} pubDate={entry.data.published} class="mb-6 rounded-xl license-container onload-animation"></License>}
</div>
</div>
+2 -3
View File
@@ -1,7 +1,6 @@
import rss from '@astrojs/rss';
import sanitizeHtml from 'sanitize-html';
import MarkdownIt from 'markdown-it';
import { getCollection } from 'astro:content';
import { siteConfig } from '@/config';
import { parse as htmlParser } from 'node-html-parser';
import { getImage } from 'astro:assets';
@@ -27,7 +26,7 @@ export async function GET(context: APIContext) {
for (const post of posts) {
// convert markdown to html string
const body = markdownParser.render(post.body);
const body = markdownParser.render(post.body ?? '');
// convert html string to DOM-like structure
const html = htmlParser.parse(body);
// hold all img tags in variable images
@@ -66,7 +65,7 @@ export async function GET(context: APIContext) {
title: post.data.title,
description: post.data.description,
pubDate: post.data.published,
link: `/posts/${post.slug}/`,
link: `/posts/${post.id}/`,
// sanitize the new html string with corrected image paths
content: sanitizeHtml(html.toString(), {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),