目录结构(Directory-structure)🔥
记录 Hugo 如何划分目录功能。
官方文档: https://gohugo.io/getting-started/directory-structure/
项目目录结构:
example/
├── archetypes/
│ └── default.md
├── assets/
├── content/
├── data/
├── layouts/
├── public/
├── static/
├── themes/
└── config.toml
config.toml —— 存放配置
官方文档:
配置可以统一记录在一个文件中:
1contentDir = "content/en"
2defaultContentLanguage = "en"
3defaultContentLanguageInSubdir = false
4[[menu.main]]
5 name = "GitHub"
6 weight = 50
7 url = "https://github.com/google/docsy/"
8 pre = "<i class="fa-brands fa-github"></i>"
9 post = "<span class='alert'>New!</span>"
10[languages]
11[languages.en]
12title = "Docsy"
13description = "Docsy does docs"
14languageName ="English"
15# Weight used for sorting.
16weight = 1
17[languages.no]
18title = "Docsy"
19description = "Docsy er operativsystem for skyen"
20languageName ="Norsk"
21contentDir = "content/no"
22time_format_default = "02.01.2006"
23time_format_blog = "02.01.2006"
1contentDir: content/en
2defaultContentLanguage: en
3defaultContentLanguageInSubdir: false
4menu:
5 main:
6 - name: GitHub
7 weight: 50
8 url: 'https://github.com/google/docsy/'
9 pre: <i class="fa-brands fa-github"></i>
10 post: <span class='alert'>New!</span>
11languages:
12 en:
13 title: Docsy
14 description: Docsy does docs
15 languageName: English
16 weight: 1 # used for sorting
17 'no':
18 title: Docsy
19 description: Docsy er operativsystem for skyen
20 languageName: Norsk
21 contentDir: content/no
22 time_format_default: 02.01.2006
23 time_format_blog: 02.01.2006
1{
2 "contentDir": "content/en",
3 "defaultContentLanguage": "en",
4 "defaultContentLanguageInSubdir": false,
5 "menu": {
6 "main": [
7 {
8 "name": "GitHub",
9 "weight": 50,
10 "url": "https://github.com/google/docsy/",
11 "pre": "<i class="fa-brands fa-github"></i>",
12 "post": "<span class='alert'>New!</span>"
13 }
14 ]
15 },
16 "languages": {
17 "en": {
18 "title": "Docsy",
19 "description": "Docsy does docs",
20 "languageName": "English",
21 "weight": 1
22 },
23 "no": {
24 "title": "Docsy",
25 "description": "Docsy er operativsystem for skyen",
26 "languageName": "Norsk",
27 "contentDir": "content/no",
28 "time_format_default": "02.01.2006",
29 "time_format_blog": "02.01.2006"
30 }
31 }
32}
新版配置文件名使用
hugo.yaml
/hugo.toml
/hugo.json
。当然,向上兼容。
为了便于管理,也可以将其拆分为多个文件。
另一个好处是可以配置多个场景(profile)以应对不同情况的配置需求,比如production
是发布时使用的配置,staging
是本地预览时使用的配置。
1├── config
2│ ├── _default
3│ │ ├── config.toml
4│ │ ├── languages.toml
5│ │ ├── menus.en.toml
6│ │ ├── menus.zh.toml
7│ │ └── params.toml
8│ ├── production
9│ │ ├── config.toml
10│ │ └── params.toml
11│ └── staging
12│ ├── config.toml
13│ └── params.toml
archetypes —— 文章原型
通过 hugo new <文件名>.md
命令生成的 .md
文章会自动填充 archetypes/default.md
模板定义的内容。
assets —— 待加工资源
这里的文件可以被 Hugo Pipes 调用并处理,然后发布到 public/
目录。
官方文档:
- “Hugo Pipes” https://gohugo.io/hugo-pipes/
static —— 静态资源
存放静态文件,比如图片、CSS、JS
区别
assets/
和static/
目录:
assets/
—— 经过 Hugo Pipes 加工后才移动static/
—— 原封不动的移动到public/
目录
layouts —— 页面布局
转跳: 页面布局
themes —— 主题
一般将主题放进去后就不用管了。
Tips: 遇到问题可以直接看主题下的源码,有时比翻文档直接、快捷。前提需要对 Hugo 机制熟悉。
├── layouts
└── themes
└── mytheme
└── layouts
├── 404.html // 404页面模板
├── _default
│ ├── baseof.html // 默认的基础模板页, 使用的方式是'拼接', 而不是'继承'.
│ ├── list.html // 列表模板
│ └── single.html // 单页模板
├── index.html // 首页模板
└── partials // 局部模板, 通过partial引入
├── footer.html
├── header.html
└── head.html
content —— 内容管理
转跳: 内容管理
data —— 站点数据
官方文档:
- “Data templates” https://gohugo.io/templates/data-templates/
这里定义的数据可以在 config.yaml
中使用或者在 layouts/
中通过 $.Site.Data
获取。
e.g.
1discography = ['1974 - Modern American Music … Period! The Criteria Sessions', '1974 - Jaco', '1976 - Jaco Pastorius', '1981 - Word of Mouth', '1981 - The Birthday Concert (released in 1995)', '1982 - Twins I & II (released in 1999)', '1983 - Invitation', '1986 - Broadway Blues (released in 1998)', '1986 - Honestly Solo Live (released in 1990)', '1986 - Live In Italy (released in 1991)', "1986 - Heavy'n Jazz (released in 1992)", '1991 - Live In New York City, Volumes 1-7.', '1999 - Rare Collection (compilation)', '2003 - Punk Jazz: The Jaco Pastorius Anthology (compilation)', '2007 - The Essential Jaco Pastorius (compilation)']
1discography:
2- 1974 - Modern American Music … Period! The Criteria Sessions
3- 1974 - Jaco
4- 1976 - Jaco Pastorius
5- 1981 - Word of Mouth
6- 1981 - The Birthday Concert (released in 1995)
7- 1982 - Twins I & II (released in 1999)
8- 1983 - Invitation
9- 1986 - Broadway Blues (released in 1998)
10- 1986 - Honestly Solo Live (released in 1990)
11- 1986 - Live In Italy (released in 1991)
12- 1986 - Heavy'n Jazz (released in 1992)
13- 1991 - Live In New York City, Volumes 1-7.
14- 1999 - Rare Collection (compilation)
15- '2003 - Punk Jazz: The Jaco Pastorius Anthology (compilation)'
16- 2007 - The Essential Jaco Pastorius (compilation)
1{
2 "discography": [
3 "1974 - Modern American Music … Period! The Criteria Sessions",
4 "1974 - Jaco",
5 "1976 - Jaco Pastorius",
6 "1981 - Word of Mouth",
7 "1981 - The Birthday Concert (released in 1995)",
8 "1982 - Twins I \u0026 II (released in 1999)",
9 "1983 - Invitation",
10 "1986 - Broadway Blues (released in 1998)",
11 "1986 - Honestly Solo Live (released in 1990)",
12 "1986 - Live In Italy (released in 1991)",
13 "1986 - Heavy'n Jazz (released in 1992)",
14 "1991 - Live In New York City, Volumes 1-7.",
15 "1999 - Rare Collection (compilation)",
16 "2003 - Punk Jazz: The Jaco Pastorius Anthology (compilation)",
17 "2007 - The Essential Jaco Pastorius (compilation)"
18 ]
19}
layouts/home.html
1<ul>
2 {{ range $.Site.Data.jazz.bass.jacopastorius.discography }}
3 <li>{{ . }}</li>
4 {{ end }}
5</ul>
public —— 发布目录
用于存放生成的站点文件
1public/
2├── categories/
3│ ├── index.html
4│ └── index.xml <-- RSS feed for this section
5├── post/
6│ ├── my-first-post/
7│ │ └── index.html
8│ ├── index.html
9│ └── index.xml <-- RSS feed for this section
10├── tags/
11│ ├── index.html
12│ └── index.xml <-- RSS feed for this section
13├── index.html
14├── index.xml <-- RSS feed for the site
15└── sitemap.xml
Last modified November 4, 2023: Correcting content dir (da1a055)