跳到主要内容

hugo菜单配置语法

最后更新于:

问题

  1[[main]]
  2name = '🏡 首页'
  3url = '/'
  4weight = 1.0
  5
  6
  7[[main]]
  8identifier = 'tech'
  9name = '📚 技术分类'
 10url = '#'
 11weight = 2.0
 12
 13[[main]]
 14name = '🖥️ 运维'
 15parent = 'tech'
 16url = '/linux/'
 17weight = 3.0
 18
 19[main.params]
 20icon = 'monitor'
 21
 22[[main]]
 23name = '🎨 前端'
 24parent = 'tech'
 25url = '/frontend/'
 26weight = 4.0
 27
 28[main.params]
 29icon = 'code'
 30
 31[[main]]
 32name = '💻 编程'
 33parent = 'tech'
 34url = '/code/'
 35weight = 5.0
 36
 37[main.params]
 38icon = 'code-slash'
 39
 40[[main]]
 41name = '🔐 黑客'
 42parent = 'tech'
 43url = '/hacker/'
 44weight = 6.0
 45
 46
 47
 48
 49
 50
 51
 52[main.params]
 53icon = 'shield'
 54
 55[[main]]
 56identifier = 'topics'
 57name = '🛠️ 专题'
 58url = '#'
 59weight = 7.0
 60
 61[[main]]
 62name = '📝 博客搭建'
 63parent = 'topics'
 64url = '/topic/'
 65weight = 8.0
 66
 67[main.params]
 68icon = 'book'
 69
 70[[main]]
 71name = '🎯 前端Demo'
 72parent = 'topics'
 73url = '/topic/qianduan-demo/'
 74weight = 9.0
 75
 76[main.params]
 77icon = 'layout'
 78
 79[[main]]
 80name = '🔧 Git'
 81parent = 'topics'
 82url = '/topic/git/'
 83weight = 10.0
 84
 85[main.params]
 86icon = 'git-branch'
 87
 88[[main]]
 89name = '💼 面试'
 90parent = 'topics'
 91url = '/topic/mianshi/'
 92weight = 11.0
 93
 94[main.params]
 95icon = 'briefcase'
 96
 97[[main]]
 98name = '🗄️ NAS'
 99parent = 'topics'
100url = '/topic/nas/'
101weight = 12.0
102
103[main.params]
104icon = 'database'
105
106[[main]]
107name = '📜 脚本'
108parent = 'topics'
109url = '/topic/scripts/'
110weight = 13.0
111
112[main.params]
113icon = 'file-code'
114
115[[main]]
116name = '🔨 工具'
117parent = 'topics'
118url = '/tools/'
119weight = 14.0
120
121[main.params]
122icon = 'tool'
123
124[[main]]
125name = '🌟 开源项目'
126parent = 'topics'
127url = '/topic/opensource/'
128weight = 15.0
129
130[main.params]
131icon = 'github'
132
133[[main]]
134identifier = 'fun'
135name = '🏓 娱乐'
136url = '#'
137weight = 16.0
138
139[[main]]
140name = '📷 相册'
141parent = 'fun'
142url = '/fun/photo/'
143weight = 17.0
144
145[main.params]
146icon = 'camera'
147
148[[main]]
149name = '🎬 电影'
150parent = 'fun'
151url = '/fun/movie/'
152weight = 18.0
153
154[main.params]
155icon = 'film'
156
157[[main]]
158name = '🎵 音乐'
159parent = 'fun'
160url = '/fun/music/'
161weight = 19.0
162
163[main.params]
164icon = 'music'
165
166[[main]]
167identifier = 'index'
168name = '👏 索引'
169url = '#'
170weight = 20.0
171
172[[main]]
173name = '📃 分类页'
174parent = 'index'
175url = '/categories/'
176weight = 22.0
177
178[main.params]
179icon = 'folder'
180
181[[main]]
182name = '🔖 标签页'
183parent = 'index'
184url = '/tags/'
185weight = 21.0
186
187[main.params]
188icon = 'tag'
189
190[[main]]
191name = '📚 归档页'
192parent = 'index'
193url = '/archives/'
194weight = 23.0
195
196[main.params]
197icon = 'archive'
198
199[[main]]
200name = '📋 清单页'
201parent = 'index'
202url = '/list/'
203weight = 24.0
204
205[main.params]
206icon = 'list'
207
208[[main]]
209identifier = 'about'
210name = '🍷 关于'
211url = '#'
212weight = 25.0
213
214[[main]]
215name = '👋 关于我'
216parent = 'about'
217url = '/about/'
218weight = 26.0
219
220[main.params]
221icon = 'user'
222
223[[main]]
224name = '🎉 关于本站'
225parent = 'about'
226url = '/about/website/'
227weight = 27.0
228
229[main.params]
230icon = 'info'
231
232[[main]]
233name = '💖 友链'
234parent = 'about'
235url = '/about/friend-links/'
236weight = 28.0
237
238[main.params]
239icon = 'link'
240
241[[main]]
242name = '🌐 网站导航'
243parent = 'about'
244url = '/about/websites/'
245weight = 29.0
246
247[main.params]
248icon = 'compass'
249
250[[main]]
251name = '👂 留言区'
252parent = 'about'
253url = '/about/liuyanqu/'
254weight = 30.0
255
256[main.params]
257icon = 'message'
258
259[[main]]
260name = '💡 思考'
261parent = 'about'
262url = '/about/thinking/'
263weight = 31.0
264
265[main.params]
266icon = 'lightbulb'
267
268[[main]]
269name = '⏱️ 时间轴'
270parent = 'about'
271url = 'https://wiki.xxdevops.cn/'
272weight = 32.0
273
274[main.params]
275external = true
276icon = 'clock'
277target = '_blank'
278
279[[main]]
280name = '📊 网站统计'
281parent = 'about'
282url = 'https://umami.xxdevops.cn/share/qccg5h22ZNjycizb/xxdevops.cn'
283weight = 33.0
284
285[main.params]
286external = true
287icon = 'bar-chart'
288target = '_blank'
289
290[[main]]
291name = '🔍 站点监控'
292parent = 'about'
293url = 'https://status.xxdevops.cn/status/dashboard'
294weight = 34.0
295
296[main.params]
297external = true
298icon = 'activity'
299target = '_blank'
300
301[[main]]
302name = '🙏 致谢名单'
303parent = 'about'
304url = '/about/thanks/'
305weight = 35.0
306
307[main.params]
308icon = 'heart'
309
310这里的用法是什么?

这是 Hugo / FixIt / Stack 等静态博客主题 里最常见的 菜单配置语法,格式是 TOML,作用是定义网站顶部导航栏(菜单)结构

我给你用最简单、最清晰的方式讲清楚每一段是干嘛的:


1. 整体作用

这段配置用来生成网站的顶部导航菜单,包括:

  • 一级菜单(首页、技术分类、专题、娱乐、索引、关于…)
  • 二级下拉菜单(运维、前端、编程、博客搭建、相册、电影…)
  • 菜单图标、链接、权重排序、是否新窗口打开等

2. 核心语法解释

[[main]]

表示一个菜单项

  • 多个 [[main]] 就代表多个菜单
  • 顺序由 weight 决定,不是写的顺序

② 常用字段

1name = '🏡 首页'        # 菜单显示文字
2url = '/'               # 点击跳转的链接
3weight = 1.0            # 排序权重,数字越小越靠前
4identifier = 'tech'     # 菜单唯一标识,用于父子关联
5parent = 'tech'         # 父菜单 ID,写了就是二级菜单

[main.params]

给菜单加附加参数,常见:

1icon = 'monitor'        # 菜单图标(Font Awesome)
2external = true         # 标记为外部链接
3target = '_blank'       # 在新标签页打开

3. 结构示例(你这段的逻辑)

 1首页
 2├─ 技术分类
 3│  ├─ 运维
 4│  ├─ 前端
 5│  ├─ 编程
 6│  └─ 黑客
 7├─ 专题
 8│  ├─ 博客搭建
 9│  ├─ 前端Demo
10│  ├─ Git
11│  ├─ 面试
12│  ├─ NAS
13│  ├─ 脚本
14│  ├─ 工具
15│  └─ 开源项目
16├─ 娱乐
17│  ├─ 相册
18│  ├─ 电影
19│  └─ 音乐
20├─ 索引
21│  ├─ 分类页
22│  ├─ 标签页
23│  ├─ 归档页
24│  └─ 清单页
25└─ 关于
26   ├─ 关于我
27   ├─ 关于本站
28   ├─ 友链
29   ├─ 网站导航
30   ├─ 留言区
31   ├─ 思考
32   ├─ 时间轴(外链)
33   ├─ 网站统计(外链)
34   ├─ 站点监控(外链)
35   └─ 致谢名单

4. 你配置里的小问题(我顺便帮你指出来)

你有几处 [main.params] 写错位了,会不生效

例如:

1[[main]]
2name = '🖥️ 运维'
3parent = 'tech'
4url = '/linux/'
5weight = 3.0
6
7[main.params]   # ← 这个属于“黑客”菜单,不属于“运维”
8icon = 'monitor'

正确写法应该是:

1[[main]]
2name = '🖥️ 运维'
3parent = 'tech'
4url = '/linux/'
5weight = 3.0
6[main.params]
7icon = 'monitor'

你现在几乎所有图标都绑错菜单了。


5. 总结一句话

这是 Hugo 博客主题的菜单配置(TOML 格式),用来控制网站顶部导航的:

  • 显示名称
  • 链接
  • 层级(一级/二级下拉)
  • 排序
  • 图标
  • 是否外链新窗口打开

如果你需要,我可以帮你把这份配置修正成完全正确、图标不错位的版本

最新文章

文档导航