惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
雷峰网
雷峰网
博客园_首页
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
小众软件
小众软件
D
Docker
P
Proofpoint News Feed
B
Blog
Vercel News
Vercel News
B
Blog RSS Feed
U
Unit 42
月光博客
月光博客
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
I
InfoQ
Recent Announcements
Recent Announcements

Donghai's Blog

使用DBeaver连接Dynamics 365 Dataverse | Donghai C# 技术备忘 - LINQ | Donghai 为Astro站点添加Google Analytics | Donghai C# 技术备忘 - LINQ - Donghai’s Blog 20260819 说些什么 | Donghai Dynamics 365 interview questions | Donghai C# 技术备忘 (1) | Donghai Dynamics 365 事件框架、事件执行管道 | Donghai 马拉松配速表 | Donghai 马拉松赛事分级 | Donghai 抖音创作日志(2026年) | Donghai 2026年跑步日志(5月开始) | Donghai 2FA | Donghai 初尝Github Actions | Donghai AstroPaper主题添加Waline评论 | Donghai Dynamics 365集中视图/聚焦视图/Focused View | Donghai AstroPaper主题添加GitHub风格的Markdown警告框 | Donghai AstroPaper主题自定义记录 | Donghai 我日常收藏的优质网站资源导航(持续更新) | Donghai 如何从归档页批量获取URL并提交到Bing Webmaster Tools | Donghai PaperMod 使用 Zeoseven 自定义网页字体 | Donghai 我常用的Prompt | Donghai Hugo默认时区导致本地预览文章不显示 | Donghai 通过手动提交工单解决Bing不收录网站问题 | Donghai 如何访问 Power BI 管理门户(Power BI Admin Portal) | Donghai 还在手敲时间戳?Win11输入法一个技巧,秒输当前时间戳 | Donghai 工作术语备忘录(持续更新) | Donghai 使用XrmToolBox导出安全角色表级权限到Excel | Donghai 24年的年终总结 | Donghai World笔记 | Donghai
AstroPaper 2.0(译) | Donghai
Donghai · 2023-01-30 · via Donghai's Blog

原文:AstroPaper 2.0

Astro 2.0 已正式发布,带来了许多酷炫的新特性、破坏性变更、开发体验(DX)改进、更好的错误提示覆盖层等。AstroPaper 也充分利用了这些新特性,尤其是 Content Collections API。

Introducing AstroPaper 2.0

Table of contents

Open Table of contents
  • 功能与变更
    • 类型安全的 Frontmatter 与重新定义的博客 Schema
    • 博客内容的新存放位置
    • 全新的内容获取 API
    • 改进的搜索逻辑,带来更好的搜索结果
    • 重命名 Frontmatter 属性
    • 博客文章的默认标签
    • 全新的预设深色主题配色
    • 自动类名排序
    • 更新的文档与 README
  • 问题修复

功能与变更

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

得益于 Astro 的 Content Collections,AstroPaper 2.0 的 Markdown Frontmatter 现在支持类型安全。博客的 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 中,当用户搜索文章时,会检索 titledescriptionheadings(即文章中所有 h1 ~ h6 标题)。

在 AstroPaper v2 中,用户输入时仅会搜索 titledescription,从而带来更精准的搜索体验。

重命名 Frontmatter 属性

以下 Frontmatter 属性已被重命名:

旧名称新名称
datetimepubDatetime
slugpostSlug

博客文章的默认标签

If a blog post doesn’t have any tag (in other words, frontmatter property tags is not specified), the default tag others will be used for that blog post. But you can set the default tag in the /src/content/_schemas.ts file.

如果某篇博客文章没有设置标签(即未指定 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 设计的深色配色方案(高对比与低对比版本)。更多信息请查看此链接:https://astro-paper.pages.dev/posts/predefined-color-schemes#astro-dark

New Predefined Dark Color Scheme

自动类名排序

AstroPaper 2.0 集成了 TailwindCSS 的 Prettier 插件,实现自动类名排序功能:

https://tailwindcss.com/blog/automatic-class-sorting-with-prettier

更新的文档与 README

所有带有 #docs 标签的博客文章以及 README 文档都已更新,以适配 AstroPaper v2。

问题修复

  • 修复博客文章页面中标签显示异常的问题
  • 在标签页面中,将面包屑导航的最后一部分统一为小写,以保持一致性
  • 在标签页面中排除草稿文章
  • 修复页面刷新后 onChange 值未更新的问题

(完)

如果这篇文章刚好帮到了你,欢迎请我喝杯咖啡