Astro 2.0 已经发布,带来了一些很酷的功能、重大变更、DX(开发体验)改进、更好的错误提示覆盖层等等。AstroPaper 利用了这些很酷的功能,特别是 Content Collections API。

目录
功能与变更
类型安全的前言和重新定义的博客 Schema
得益于 Astro 的 Content Collections,AstroPaper 2.0 markdown 内容的前言现在类型安全了。博客 Schema 定义在 src/content/_schemas.ts 文件中。
博客内容的新家
所有博客文章已从 src/contents 移动到 src/content/blog 目录。
新的获取 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。
重命名的前言属性
以下前言属性已重命名。
| 旧名称 | 新名称 |
|---|---|
| datetime | pubDatetime |
| slug | postSlug |
博客文章的默认标签
如果博客文章没有任何标签(换句话说,未指定前言属性 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 的深色 logo。查看此链接了解更多信息。
自动类名排序
AstroPaper 2.0 包含使用 TailwindCSS Prettier 插件的自动类名排序功能。
更新的文档和 README
所有 #docs 博客文章和 README 都已针对此 AstroPaper v2 进行了更新。
错误修复
- 修复了博客文章页面中损坏的标签
- 在标签页面中,面包屑导航的最后一部分现已更新为小写,以保持一致性
- 在标签页面中排除草稿文章
- 修复了页面重新加载后“onChange 值未更新”的问题