cd /Users/neilsu/Data/Codespace/blog/syccxdr.github.io
hugo new content posts/my-new-post.md这会在 content/posts/ 下生成一个 Markdown 文件,自动填好日期等 front matter。
打开生成的文件,编辑 front matter 和正文:
---
title: "文章标题"
date: 2026-02-19T16:00:00+08:00
draft: false # 改为 false 才会发布
tags: ["标签1", "标签2"]
author: "syccxdr"
showToc: true # 显示目录
TocOpen: false # 目录默认折叠
description: "文章摘要,会显示在列表页"
cover:
image: "" # 封面图片路径(可选)
alt: ""
caption: ""
---
正文内容写在这里...hugo server -D打开 http://localhost:1313 查看效果。-D 参数会同时显示 draft: true 的草稿。
确认没问题后 Ctrl+C 停止服务器。
git add content/posts/my-new-post.md
git commit -m "发布: 文章标题"
git push推送到 main 分支后,GitHub Actions 会自动构建并部署,大约 1-2 分钟后生效。
| 字段 | 说明 | 示例 |
|---|---|---|
title |
文章标题 | "我的文章" |
date |
发布日期 | 2026-02-19T16:00:00+08:00 |
draft |
是否为草稿 | false |
tags |
标签列表 | ["Go", "教程"] |
author |
作者 | "syccxdr" |
description |
摘要 | "这篇文章讲了..." |
showToc |
显示目录 | true |
TocOpen |
目录默认展开 | false |
weight |
排序权重(越小越靠前) | 1 |
cover.image |
封面图片 | "images/cover.png" |
```python
print("hello")
```图片文件放在文章同名目录下(使用 Page Bundle 方式):
content/posts/my-new-post/
├── index.md # 文章内容
└── images/
└── example.png # 图片
使用 Page Bundle 时,创建文章的方式稍有不同:
mkdir -p content/posts/my-new-post/images
touch content/posts/my-new-post/index.md在 hugo.yaml 中启用 KaTeX 后可使用:
行内公式:$E = mc^2$
独立公式:
$$
\int_0^\infty f(x) dx
$$# 创建新文章
hugo new content posts/文章名.md
# 本地预览(含草稿)
hugo server -D
# 本地预览(不含草稿,模拟生产环境)
hugo server
# 构建静态文件
hugo --minify
# 查看站点状态
git status
git log --oneline -5