Skip to content
Dust In The Wind
Go back

AstroPaper 2.0

Edit page

Astro 2.0 已发布,带来了很多酷炫功能、breaking changes、开发体验改进、更友好的错误提示等。AstroPaper 充分利用了这些特性,特别是 Content Collections API。

Introducing AstroPaper 2.0

Table of contents

Open Table of contents

功能与变更

类型安全的 Frontmatter 与重新定义的博客 Schema

AstroPaper 2.0 的 Markdown 内容 frontmatter 现在是类型安全的,得益于 Astro 的 Content Collections。博客 Schema 定义在 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 搜索时会匹配 titledescriptionheadings(所有 h1~h6 标题)。AstroPaper v2 中,用户输入时只搜索 titledescription

重命名的 Frontmatter 属性

以下 frontmatter 属性进行了重命名:

旧名称新名称
datetimepubDatetime
slugpostSlug

博客文章默认标签

如果文章没有指定任何标签(即 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 暗色 logo 的暗色配色方案(高对比度 & 低对比度)。详见此链接

New Predefined Dark Color Scheme

自动 Class 排序

AstroPaper 2.0 集成了 TailwindCSS Prettier 插件,自动排序 class。

更新文档与 README

所有 #docs 博客文章和 README 均已针对 AstroPaper v2 更新。

Bug 修复

  • 修复博客文章页面标签显示异常
  • 标签页面中,面包屑最后一部分统一改为小写
  • 标签页面排除草稿文章
  • 修复页面重载后 ‘onChange 值不更新’ 的问题

Edit page