Hexo使用攻略:添加分类及标签
本教程针对的是Mac环境
Hexo创建”分类”选项
生成”分类”页并添加type属性
打开命令行,
cd
进入博客所在文件夹。执行命令hexo new page categories
,来新建一个页面,并命名为categories。成功后会提示:INFO Created: ~/hexo/source/categories/index.md
根据上面的路径找到index.md这个文件,打开后默认内容如下:
1
2
3
4---
title: categories
date: 2018-10-25 20:11:37
---编辑新创建的页面,添加
type: "categories"
到内容中(注意,这些属性和属性值之间必须有一个空格),主题将自动为这个页面显示所有分类,添加后是这样的:1
2
3
4
5---
title: categories
date: 2018-10-25 20:11:37
type: "categories"
---保存并关闭文件。
给文章添加”categories”属性
打开需要添加分类的文章,为其添加categories属性。下方的
categories: Python
表示添加这篇文章到“Python”这个分类中。注意:Hexo中一篇文章只能属于一个分类,也就是说如果在”Python”下方添加”-xxx”,Hexo不会产生两个分类,而是把分类嵌套,即该文章属于”Python“下的”-xxx“分类。
1
2
3
4---
title: Python中*args和**kwargs的用法总结
categories: Python
---回到hexo文件夹下,依次执行
hexo g
,hexo server
和hexo deploy
命令(重新部署)。
在Hexo菜单上添加分类选项
cd
进/hexo/themes/hexo-theme-next-5.1.4
文件夹内,编辑该目录下的_config.yml文件(把链接加上),将源代码:1
2
3
4
5
6
7
8
9
10
11
12
13menu:
home: / || home
#about: /about/ || user
#tags: /tags/ || tags
#categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
# Enable/Disable menu icons.
menu_icons:
enable: true改为:
1
2
3
4
5
6
7
8
9
10
11
12
13menu:
home: / || home
#about: /about/ || user
#tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
# Enable/Disable menu icons.
menu_icons:
enable: true即将menu中的
categories:/categories || th
的注释去掉,然后保存并退出。回到
hexo
文件夹下,依次执行hexo g
,hexo server
和hexo deploy
命令,即可看到菜单栏中新增了一个Categories选项。
至此,成功给文章添加分类,点击Index上的Categories可以看到所有的分类情况,再点击该分类就可以看到该分类下的所有文章。当然,前提是添加了categories: xxx字段。
Hexo创建”标签”选项
生成”标签”页并添加type属性
打开命令行,
cd
进入博客所在文件夹。执行命令hexo new page tags
,来新建一个页面,并命名为tags。成功后会提示:INFO Created: ~/hexo/source/tags/index.md
根据上面的路径找到index.md这个文件,打开后默认内容如下:
1
2
3
4---
title: tags
date: 2018-10-25 21:11:00
---编辑新创建的页面,添加
type: "tags"
到内容中,主题将自动为这个页面显示所有分类,添加后是这样的:1
2
3
4
5---
title: tags
date: 2018-10-25 21:11:00
type: "tags"
---保存并关闭文件。
给文章添加”tags”属性
打开需要添加标签的文章,为其添加tags属性。下方的
tags: Django
表示添加这篇文章到“Django”这个标签中。1
2
3
4---
title: Python中*args和**kwargs的用法总结
tags: Django
---回到hexo文件夹下,依次执行
hexo g
,hexo server
和hexo deploy
命令(重新部署)。
在Hexo菜单上添加标签选项
cd
进/hexo/themes/hexo-theme-next-5.1.4
文件夹内,编辑该目录下的_config.yml文件(把链接加上),将源代码:1
2
3
4
5
6
7
8
9
10
11
12
13menu:
home: / || home
#about: /about/ || user
#tags: /tags/ || tags
#categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
# Enable/Disable menu icons.
menu_icons:
enable: true改为:
1
2
3
4
5
6
7
8
9
10
11
12
13menu:
home: / || home
#about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
# Enable/Disable menu icons.
menu_icons:
enable: true即将menu中的
tags: /tags/ || tags
的注释去掉,然后保存并退出。回到
hexo
文件夹下,依次执行hexo g
,hexo server
和hexo deploy
命令,即可看到菜单栏中新增了一个tags选项。
引用文章:
1.Hexo使用攻略-添加分类及标签 | linlif-blog