𝑨𝑻𝒂𝒓𝒂𝒙𝑳

如何写文章并发布到博客

每一篇文章就是一个 Markdown 文件,也就是 .md 文件。

例如:

1content/blog/my-new-post.md

这个文件最终会变成一篇博客文章。


一篇文章的基本结构

一篇 Hugo 文章通常由两部分组成:

  1. Front Matter:文章信息,比如标题、日期、标签
  2. 正文内容:你真正写的文章内容

最小示例:

 1---
 2title: "My New Post"              # 文章标题,会显示在页面上
 3date: 2026-04-29T00:00:00+08:00   # 发布时间
 4draft: false                      # 是否为草稿;false 表示发布,true 表示草稿
 5slug: "my-new-post"               # 文章链接,最终地址是 /my-new-post/
 6tags: ["Hugo", "Notes"]           # 标签,可以写多个
 7description: "A short summary."   # 文章简介,用于 SEO 和分享预览
 8---
 9
10## What This Is About
11
12这里开始写正文。
13
14## Notes
15
16这里写主要内容。
17
18## Summary
19
20这里写总结。

注意:--- 上下两段之间的内容就是 Front Matter。不要随便删掉。


Front Matter 字段说明

title

文章标题。

1title: "My New Post"

它会显示在:


date

文章发布时间。

1date: 2026-04-29T00:00:00+08:00

其中:


draft

是否为草稿。

1draft: true   # 草稿,本地预览加 -D 才能看到
2draft: false  # 正式发布,网站上会显示

如果你写完了,想让文章显示在网站上,就改成:

1draft: false

slug

文章链接。

1slug: "my-new-post"

因为你现在的 hugo.toml 里设置了:

1[permalinks]
2  blog = "/:slug/"  # blog 文章使用 slug 作为最终链接

所以这篇文章的网址会是:

1http://localhost:1313/my-new-post/

建议 slug 用英文、小写、短横线:

1good-example
2how-to-write-posts
3my-first-project

不太建议:

1我的第一篇文章
2My New Post!!!
3post 123

tags

文章标签。

1tags: ["Hugo", "Writing", "Notes"]

标签用来分类文章。不要写太多,2~4 个就够了。


description

文章简介。

1description: "A short guide for writing posts on this blog."

它主要用于:


新建一篇博客文章

在 PowerShell 里运行:

1& "E:\系统\桌面\hugo\dev\hugo.exe" new content blog/my-new-post.md
2# ↑ 使用当前项目里的 hugo.exe 新建一篇文章
3# ↑ 文件会生成在 content/blog/my-new-post.md

然后打开这个文件:

1E:\系统\桌面\hugo\dev\content\blog\my-new-post.md

把里面的:

1draft: true

改成:

1draft: false

然后开始写正文。


本地预览博客

启动本地服务器:

1& "E:\系统\桌面\hugo\dev\hugo.exe" server --source "E:\系统\桌面\hugo\dev" -D
2# server:启动本地预览服务器
3# --source:指定你的 Hugo 项目目录
4# -D:显示 draft = true 的草稿文章

然后打开浏览器访问:

1http://localhost:1313

如果你只是想看正式发布内容,也可以不用 -D

1& "E:\系统\桌面\hugo\dev\hugo.exe" server --source "E:\系统\桌面\hugo\dev"

发布前检查清单

写完文章后,检查这些东西:


推荐写作结构

如果不知道怎么开始,可以直接用这个结构:

 1## Why I Wrote This
 2
 3写为什么要写这篇文章。
 4
 5## What I Learned
 6
 7写你学到了什么。
 8
 9## Notes
10
11写具体过程、资料、代码、想法。
12
13## Summary
14
15写最后的总结。

如果是中文文章,可以改成:

1## 为什么写这篇
2
3## 我学到了什么
4
5## 具体记录
6
7## 总结

一个完整模板

你可以复制下面这份,改一改就能用:

 1---
 2title: "文章标题"                  # 页面显示的标题
 3date: 2026-04-29T00:00:00+08:00   # 发布时间
 4draft: false                      # false 表示发布
 5slug: "post-url"                  # 文章网址,例如 /post-url/
 6tags: ["Tag1", "Tag2"]            # 文章标签
 7description: "一句话介绍这篇文章。" # 页面描述
 8---
 9
10## 为什么写这篇
11
12这里写背景。
13
14## 正文
15
16这里写主要内容。
17
18## 总结
19
20这里写结论。

写博客最重要的不是一开始就写得很完美,而是先把想法留下来。

#Hugo #写作 #博客