几乎准备好写作

发布: (2026年2月8日 GMT+8 20:09)
2 分钟阅读
原文: Dev.to

Source: Dev.to

删除示例文章

git rm -r theme/content/posts
git add -u
git commit -m 'delete skeleton posts'

将 Front Matter 转换为 YAML

默认的 Hugo 站点和主题骨架使用 TOML front matter,但通常更推荐使用 YAML(例如,GitHub 渲染效果更好)。

cd site/
hugo convert toYAML --unsafe
cd ..

注意: 必须使用 --unsafe 标志;否则 Hugo 会返回:

ERROR command error: Unsafe operation not allowed, use --unsafe or set a different output path

更新 archetypes 以使用 YAML front matter

--- a/theme/archetypes/default.md
+++ b/theme/archetypes/default.md
@@ -1,5 +1,5 @@
-+++
-date = '{{ .Date }}'
-draft = true
-title = '{{ replace .File.ContentBaseName "-" " " | title }}'
-+++
+---
+title: "{{ replace .File.ContentBaseName `-` ` ` | title }}"
+date: "{{ .Date }}"
+draft: true
+---

添加第一个章节(Devlog)

创建章节文件夹和索引文件:

mkdir theme/content/devlog
touch theme/content/devlog/_index.md

theme/content/devlog/_index.md 中添加 front matter:

---
title: "Devlog"
---

在菜单中显示

更新 theme/hugo.toml,将默认的 “Posts” 菜单项替换为 “Devlog”:

--- a/theme/hugo.toml
+++ b/theme/hugo.toml
@@ -9,8 +9,8 @@ title = 'My New Hugo Site'
     weight = 10

   [[menus.main]]
-    name = 'Posts'
-    pageRef = '/posts'
+    name = 'Devlog'
+    pageRef = '/devlog'
     weight = 20

   [[menus.main]]

最后一步

清理 site/content/_index.md(该文件包含首页内容)。
现在,你已经准备好编写并发布你的 Hugo 站点了。

0 浏览
Back to Blog

相关文章

阅读更多 »

使用 Git Alias 成为高手

《Use Git Alias To Become Pro》的封面图片:https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-up...