文章写作
创建标准博客文章
文章写作
文章是 PrimeEdge 的主要内容类型,适合发布长文博客。
创建文章
hugo new content posts/my-first-post.md
文章 Front Matter
---
title: "文章标题"
description: "文章描述,用于 SEO 和摘要"
date: 2024-01-15T10:00:00+08:00
lastmod: 2024-01-16T12:00:00+08:00
draft: false
tags: ["hugo", "tutorial"]
categories: ["技术"]
author: "作者名"
featured: true # 是否设为精选
comments: true # 是否开启评论
toc: true # 是否显示目录
cover: "/images/cover.jpg" # 封面图
---
Front Matter 字段说明
| 字段 | 必填 | 说明 |
|---|---|---|
title |
是 | 文章标题 |
description |
否 | 文章描述,SEO 和列表摘要使用 |
date |
是 | 发布日期 |
lastmod |
否 | 最后修改日期 |
draft |
否 | 草稿状态,true 时不发布 |
tags |
否 | 标签数组 |
categories |
否 | 分类数组 |
author |
否 | 作者名,覆盖默认作者 |
featured |
否 | 设为精选文章 |
comments |
否 | 是否开启评论,默认 true |
toc |
否 | 是否显示目录,默认 true |
cover |
否 | 封面图路径 |
封面图
设置封面图
---
cover: "/images/my-cover.jpg"
---
封面图建议
- 尺寸: 1200x630 像素(推荐)
- 格式: WebP 或 JPG
- 大小: 控制在 200KB 以内
- 内容: 与文章主题相关,避免纯文字
自动生成封面
如果不设置封面图,文章列表会显示默认占位图。
文章摘要
PrimeEdge 自动提取文章前 150 字符作为摘要。你也可以手动设置摘要分隔符:
这是文章摘要,会显示在列表页面。
这是正文内容,不会显示在列表页面。
目录(TOC)
文章默认显示目录,基于 H2-H4 标题自动生成。
关闭目录
---
toc: false
---
目录配置
在 hugo.toml 中配置目录:
[markup.tableOfContents]
startLevel = 2 # 从 H2 开始
endLevel = 4 # 到 H4 结束
ordered = false # 无序列表
代码高亮
PrimeEdge 支持代码高亮,使用 fenced code blocks:
```python
def hello():
print("Hello, World!")
```
行号和高亮
```python {linenos=table,hl_lines=[2,3]}
def hello():
# 这行会高亮
print("Hello, World!") # 这行也会高亮
return True
```
引用图片
普通图片

带标题的图片

使用 Hugo Figure
{{< figure src="/images/photo.jpg" title="图片标题" caption="图片描述" >}}
链接卡片
在文章中插入链接卡片:
{{< link-card title="标题" url="https://example.com" desc="描述" >}}
文章模板
创建 archetypes/posts.md 作为文章模板:
---
title: "{{ replace .Name "-" " " | title }}"
description: ""
date: {{ .Date }}
draft: true
tags: []
categories: []
toc: true
comments: true
---
<!--more-->
文章组织
按日期组织
content/posts/
├── 2024/
│ ├── 01/
│ │ └── my-post.md
│ └── 02/
│ └── another-post.md
└── _index.md
按分类组织
content/posts/
├── tech/
│ └── hugo-guide.md
├── life/
│ └── travel-diary.md
└── _index.md
精选文章
标记为精选的文章会在首页优先展示:
---
featured: true
---
定时发布
设置未来的日期,Hugo 会在该日期后自动发布:
---
date: 2024-12-25T00:00:00+08:00
---
文章写作建议
- 标题: 简洁有力,包含关键词
- 开篇: 前 150 字要吸引人,这是摘要内容
- 结构: 使用标题层级组织内容
- 图片: 适当插入图片增加可读性
- 标签: 使用 3-5 个相关标签
- 分类: 选择最相关的一个分类
Comments