Skip to content
Go back

AstroPaper 2.0

Edit page

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

Introducing AstroPaper 2.0

目录

功能和变化

类型安全的 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 中,当有人搜索某篇文章时,将搜索的搜索条件键是 titledescriptionheadings(heading 表示博客文章的所有标题 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 的深色徽标。查看此链接了解更多信息。

新的预定义深色配色方案

自动类排序

AstroPaper 2.0 包含使用 TailwindCSS Prettier 插件的自动类排序

更新的文档和 README

所有 #docs 博客文章和 README 都已为此 AstroPaper v2 更新。

错误修复


Edit page
Share this post on:

Previous Post
如何更新 AstroPaper 的依赖项
Next Post
Tailwind Typography 插件