396 字
2 分钟
在这个博客里写 Markdown
在 src/content/posts/ 里新建一个 .md 文件,就拥有了一篇新文章。文件名会成为网址的一部分,例如 hello-astro.md 对应 /posts/hello-astro/。
也可以使用主题自带的命令创建文章骨架:
pnpm new-post my-first-postFrontmatter
每篇文章顶部都需要一段 Frontmatter,用来描述标题、摘要、发布时间和分类:
---title: "文章标题"published: 2026-11-02description: "一句话摘要,会显示在列表和搜索结果里。"tags: [Astro, 写作]category: 写作draft: false---draft: true 的文章不会出现在列表里,也不会被生产构建。写完之前可以先把它藏起来。
常用语法
强调与链接
用 **粗体** 表示 粗体,用 *斜体* 表示 斜体。链接写成 [文字](https://example.com)。
列表
无序列表适合并列的内容:
- 第一项
- 第二项
- 第三项
有序列表适合步骤:
- 新建文件
- 写正文
- 运行
pnpm build
引用
引用用来强调一段独立的想法,或者引入别人的话。
它可以有多行。
代码
行内代码用反引号包起来,例如 pnpm dev。代码块则可以指定语言,获得语法高亮:
const posts = await getCollection("posts");
const sorted = posts.sort( (a, b) => b.data.published.valueOf() - a.data.published.valueOf(),);表格
| 字段 | 类型 | 必填 |
|---|---|---|
title | string | 是 |
published | date | 是 |
description | string | 否 |
tags | string[] | 否 |
category | string | 否 |
发布
保存文件后,开发服务器会自动刷新。确认排版没有问题,再执行构建:
pnpm build构建会检查 Frontmatter 是否符合内容集合的 schema。字段缺失或类型不对时,构建会直接报错,而不是等到线上才发现。
在这个博客里写 Markdown
https://example.com/posts/writing-markdown/分享文章
生成精美分享图或复制链接,与更多人分享本文。
继续阅读
换条路线
从其他文章中稳定抽取
最后更新于 ,距今已过 2 天
部分内容可能已过时