chore: 升级 Astro 5.16.5 → 7.3.3
依赖
- astro 5 → 7.3.3,@astrojs/{mdx,react,rss,sitemap,check}、astro-expressive-code
与 @swup/astro 同步升到最新
- 新增 @astrojs/markdown-remark(Astro 7 默认改用 Sätteri 处理器,
本项目依赖大量 remark/rehype 插件,故显式固定回 unified 管线)
内容集合迁移到 Content Layer API(Astro 6 已移除旧 API)
- src/content/config.ts → src/content.config.ts,三个集合改用 glob() loader
- z 改从 astro/zod 导入
- 所有 entry.slug → entry.id;entry.render() → render(entry)
Astro 7 兼容
- 修复 bookshelf-content.astro 里多行 {/* */} 注释导致的 Rust 编译器
"Unterminated regular expression"
- 删除该文件里一处多余的 </div>(旧 Go 编译器会静默纠正,新编译器不会)
- global.css: @import "tailwindcss" → "tailwindcss/index.css"
(Vite 8 不再解析裸包名的 style 条件)
- astro.config.mjs 显式设置 compressHTML: true,保持 v6 的空白处理行为
验证:构建 41 页通过;与线上(Astro 5 构建)对比 39 个 URL 无一丢失,
仅新增新文章 DIY-computer 的 2 个 URL;逐页渲染文本与线上一致;
pnpm build 与 dev server 均正常。
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { defineCollection } from "astro:content"
|
||||
import { glob } from "astro/loaders"
|
||||
import { z } from "astro/zod"
|
||||
|
||||
const posts = defineCollection({
|
||||
loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/posts" }),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
published: z.date(),
|
||||
updated: z.date().optional(),
|
||||
draft: z.boolean().optional().default(false),
|
||||
description: z.string().optional().default(""),
|
||||
image: z.string().optional().default(""),
|
||||
tags: z.array(z.string()).optional().default([]),
|
||||
category: z.string().optional().nullable().default(""),
|
||||
lang: z.string().optional().default(""),
|
||||
pinned: z.boolean().optional().default(false),
|
||||
|
||||
encrypted: z.boolean().optional().default(false),
|
||||
password: z.string().optional().default(""),
|
||||
disclaimer: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
|
||||
prevTitle: z.string().default(""),
|
||||
prevSlug: z.string().default(""),
|
||||
nextTitle: z.string().default(""),
|
||||
nextSlug: z.string().default(""),
|
||||
}),
|
||||
})
|
||||
|
||||
const thoughts = defineCollection({
|
||||
loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/thoughts" }),
|
||||
schema: z.object({
|
||||
title: z.string().optional(),
|
||||
published: z.date(),
|
||||
tags: z.array(z.string()).optional().default([]),
|
||||
/** 地点,显示在日期旁 */
|
||||
location: z.string().optional(),
|
||||
/** 天气,与地点一起显示 */
|
||||
weather: z.string().optional(),
|
||||
/** 配图,public 下的绝对路径 */
|
||||
images: z.array(z.string()).optional().default([]),
|
||||
/** 置顶 */
|
||||
pinned: z.boolean().optional().default(false),
|
||||
}),
|
||||
})
|
||||
|
||||
const studies = defineCollection({
|
||||
loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/studies" }),
|
||||
// 注意:`id` 由 glob loader 从文件路径生成(Content Layer API),
|
||||
// 所以这里不声明 slug,直接读 entry.id。
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
status: z.enum(["在读", "沉淀中", "暂搁", "已结"]),
|
||||
started: z.string(), // "YYYY-MM" 或 "YYYY-MM-DD"
|
||||
subtitle: z.string().optional(),
|
||||
epigraph: z.string().optional(),
|
||||
field: z.string().optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
export const collections = { posts, thoughts, studies }
|
||||
Reference in New Issue
Block a user