按 Enter 键跳转到正文

内容写作指南:Front Matter 与排版

Front Matter 全字段

每篇文章开头用 --- 包裹的 YAML 就是 front matter。完整字段:

 1---
 2title: "文章标题"                 # 必填
 3date: 2025-01-15                  # 必填:发布时间(决定排序与归档)
 4lastmod: 2025-01-20               # 可选:详情页显示"最后更新于"
 5description: "摘要,列表页显示"    # 强烈建议手写(见"摘要"一节)
 6featured: "images/hero.jpg"       # 特色图(static/ 下路径;也可用 Page Bundle)
 7slug: "my-post"                   # 可选:URL 末尾段(默认取文件名)
 8categories: ["技术"]              # 分类(可多个)
 9tags: ["hugo", "写作"]            # 标签(可多个)
10author: "Leanku"                  # 可选:覆盖站点默认作者
11sticky: true                      # 可选:列表页显示"精选"徽标
12draft: true                       # 草稿(hugo server -D 才显示)
13keywords: ["hugo", "主题"]        # 可选:meta keywords(缺省用 tags)
14canonicalURL: ""                  # 可选:手动指定 canonical(转载声明用)
15robotsNoIndex: true               # 可选:单篇屏蔽索引
16images: ["images/hero.jpg"]       # 可选:OG/JSON-LD 图片列表(缺省取 featured)
17---

特色图:两种用法

方式说明示例
featured 参数指向 static/ 下路径featured: "images/covers/theme-intro.svg"
Page Bundle文章目录 index.md + 图片content/post/xxx/index.md + hero.jpg,自动取包内第一张图

列表页特色图统一 2:1 比例裁切object-fit: cover),建议源图 ≥ 1200×600; 本站示例用的是同比例的 SVG 封面,文字不会裁切。

摘要(Summary)写法

  • 列表卡片优先显示 description;留空则用 Hugo 自动摘要(长度由 params.excerptLength 控制), 末尾自动附加"阅读更多"按钮;
  • 中文没有空格分词,自动摘要可能从句子中间截断——务必手写 description,建议 60~120 字;
  • 摘要里的 Markdown 链接可以正常渲染([链接](https://example.com))。

分类、标签与归档

1hugo new post/my-first-post.md     # 在 post 分区创建(archetypes/post.md 模板)
  • 分类归档:/categories/技术/;标签归档:/tags/hugo/;总览页:/categories//tags/
  • 给分类/标签写描述:在 content/categories/技术/_index.md(或 tags 下)加 front matter description,会显示在归档标题条下方;
  • 按月归档:/archives/,侧栏"归档"组件与文章署名里的日期链接都指向它;
  • URL 由 [permalinks] post = "/:sections/:slug/" 决定:content/post/ai/openclaw.md/post/ai/openclaw/嵌套子分区必须建 _index.md,否则该层级不会出现在 URL 中。

正文排版要点

  • 正文链接自动加粗 + 下划线,悬停去下划线(原版主题排版习惯);
  • 支持表格、脚注、任务列表、定义列表(goldmark 已开启),示例见 代码高亮与 Markdown 进阶排版
  • markup.goldmark.renderer.unsafe = true 已开启,可直接嵌入 HTML;
  • 行内代码 `code` 与代码块 ```lang 均会自动着色(One Dark)。

写作流程建议

  1. hugo new post/xxx.md 生成草稿;
  2. 填写 front matter(标题、日期、description、featured、分类、标签);
  3. hugo server -D 边写边预览(草稿也显示);
  4. 定稿后删掉 draft: truehugo --minify && npx pagefind --site public 构建发布。

发表评论