内容是站点最基本,也是最核心的部分,本文将介绍内容的一些基本概念,以及如何创建内容。
1tree content/blog
2content/blog
3├── _index.md
4├── hello.md
5├── foo
6| ├── feature.png
7│ ├── bar.md
8│ └── index.md
9├── posts
10│ ├── _index_.md
11│ ├── post-1.md
12│ └── post-2.md
以上内容结构具有:
blog/hello/, blog/foo/、blog/posts/post-1/ 和 blog/posts/post-2/。_index.md 的目录):blog 和 posts。hello.md、posts/post-1.md 和 posts/post-2.md。index.md 的目录):foo。Leaf bundle 将作为一篇常规页面,其余的内容将作为其页面资源,如 foo/bar.md 是一个页面资源,而非单页内容。详情请查阅 Content Organization 和 Page Bundles 。
通过 hugo new 命令创建内容。
1hugo new blog/hello/index.md
该命令将于 content 目录下创建一个 blog/hello/index.md 的内容页面,其初始内容类似如下:
1---
2title: "Hello"
3date: 2023-03-08T11:02:23+08:00
4draft: true
5---
draft: true),在发布之前,可以通过指定 hugo server 的 --buildDrafts 或 -D 参数进行预览。当内容准备就绪,则需要将 draft 改为 false 或者删除 draft 以发布该内容。内容原型是用于创建内容的模板,可以定义一些初始化的参数和内容,比如以下 notes 原型指定 type 为 docs 以使用 docs 布局。
1---
2type: docs
3title: '{{ replace .Name "-" " " | title }}'
4date: {{ .Date }}
5draft: true
6---
当创建时,将会使用对应的模板生成初始内容。
1hugo new notes/foo.md
2Content "content/notes/foo.md" created
1cat content/notes/foo.md
2---
3type: docs
4title: 'Foo'
5date: 2023-04-12T14:35:35+08:00
6draft: true
7---
详情请查阅原型。
每个内容页面由前言和主体构成。
1FRONT MATTER
2
3CONTENT BODY
也就是 Front Matter,用于定义内容的参数,如标题、日期、标签、分类等。
Hugo 支持三种前言格式:YAML、TOML 和 JSON。
YAML 前言由 --- 包裹起来。
1---
2title: "Hello"
3---
TOML 前言由 +++ 包裹起来。
1+++
2title = "Hello"
3+++
JSON 前言由 { 和 } 包裹起来,后跟一个新行。
1{
2 "title": "Hello"
3}
也就是字面上的内容本身,支持 Markdown 和短代码编写内容。