Astro 2.0 已发布,具有一些很酷的功能、重大更改、DX 改进、更好的错误覆盖等。AstroPaper 利用了这些很酷的功能,尤其是 Content Collections API。

目录
功能和变化
类型安全的 Frontmatters 和重新定义的博客架构
得益于 Astro 的 Content Collections,AstroPaper 2.0 markdown 内容的 Frontmatter 现在是类型安全的。博客架构在 src/content/_schemas.ts 文件中定义。
博客内容的新家
所有博客文章都从 src/contents 移至 src/content/blog 目录。
新的 Fetch API
内容现在使用 getCollection 函数获取。不再需要指定内容的相对路径。
// 旧内容获取方法
- const postImportResult = import.meta.glob<MarkdownInstance<Frontmatter>>(
"../contents/**/**/*.md",);
// 新内容获取方法
+ const postImportResult = await getCollection("blog");
修改搜索逻辑以获得更好的搜索结果
在旧版本的 AstroPaper 中,当有人搜索某篇文章时,将搜索的搜索条件键是 title、description 和 headings(heading 表示博客文章的所有标题 h1 ~ h6)。在 AstroPaper v2 中,随着用户输入,只会搜索 title 和 description。
重命名的 Frontmatter 属性
以下 frontmatter 属性已重命名。
| 旧名称 | 新名称 |
|---|---|
| datetime | pubDatetime |
| slug | postSlug |
博客文章的默认标签
如果博客文章没有任何标签(换句话说,frontmatter 属性 tags 未指定),默认标签 others 将用于该博客文章。但您可以在 /src/content/_schemas.ts 文件中设置默认标签。
// src/contents/_schemas.ts
export const blogSchema = z.object({
// ---
// 将 "others" 替换为您想要的任何内容
tags: z.array(z.string()).default(["others"]),
ogImage: z.string().optional(),
description: z.string(),
});
新的预定义深色配色方案
AstroPaper v2 有一个新的深色配色方案(高对比度和低对比度),它基于 Astro 的深色徽标。查看此链接了解更多信息。
自动类排序
AstroPaper 2.0 包含使用 TailwindCSS Prettier 插件的自动类排序
更新的文档和 README
所有 #docs 博客文章和 README 都已为此 AstroPaper v2 更新。
错误修复
- 修复博客文章页面中损坏的标签
- 在标签页面中,面包屑的最后一部分现在更新为小写以保持一致性
- 在标签页面中排除草稿文章
- 修复页面重新加载后 ‘onChange 值未更新问题’