Hexo菜单

Hexo 主题下默认有首页和归档两个菜单,我们还可以开启其他菜单项,比如分类、标签、关于

首先打开主题下的配置文件_config.yml,然后搜索menu找到如下配置项,将about、tags、categories前的#号去掉,就开启了关于、标签和分类标签,当然还有其他菜单项也可以开启

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
---
Menu Settings
---

When running the site in a subdirectory (e.g. domain.tld/blog), remove the leading slash from link value (/archives -> archives).

Usage: `Key: /link/ || icon`
Key is the name of menu item. If the translation for this item is available, the translated text will be loaded, otherwise the Key name will be used. Key is case-senstive.
Value before `||` delimiter is the target link.
Value after `||` delimiter is the name of FontAwesome icon. If icon (with or without delimiter) is not specified, question icon will be loaded.

External url should start with http:// or https://

menu:
home: / || home
about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
schedule: /schedule/ || calendar
sitemap: /sitemap.xml || sitemap
commonweal: /404/ || heartbeat

重新生成部署后,可以看到新增的菜单项,但是单击后会报如下错误

1
2
3
Cannot GET /about/
Cannot GET /tags/
Cannot GET /categories/

这是因为你还需运行如下命令新建相关页面

1
2
3
hexo new page "about"
hexo new page "tags"
hexo new page "categories"

运行结果如下,会再source文件下创建about、tags、categories文件夹,每个文件夹下还会创建一个index.md文件表示关于、标签页分类页面,编辑这三个MarkDown文件可以自定义这三个页面的内容

1
2
3
4
5
6
7
8
D:\hexo\blog>hexo new page "about"
INFO Created: D:\hexo\blog\source\about\index.md

D:\hexo\blog>hexo new page "tags"
INFO Created: D:\hexo\blog\source\tags\index.md

D:\hexo\blog>hexo new page "categories"
INFO Created: D:\hexo\blog\source\categories\index.md

还差最后一步,打开各页面对应的index.md文件,编辑如下内容,title和date是默认生成的,增加type即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
---
title: about
date: 2019-06-25 19:16:17
type: "about"
---

---
title: about
date: 2019-06-25 19:16:17
type: "tags"
---

---
title: about
date: 2019-06-25 19:16:17
type: "categories"
---

重新生成和部署即可看到效果

查看评论