hexo开启分类和标签

问题背景

当我们使用hexo搭建完成个人博客后,分类和标签功能默认未开启,当我们点击分类和标签的页签时会发生404的错误。

解决方法

1、生成标签和分类页面

你需要在 hexo 根目录的 source 文件夹下新建一个 tags 文件夹,然后在 tags 文件夹里面新建一个 index.md 文件。快捷命令为:

1
2
hexo new page tags
hexo new page categories

2、修改index的内容

这里是配置标签页面显示tags类型的对象

1
2
3
4
5
6
---
title: 标签
date: 2020-06-13 13:37:33
type: tags
layout: tags
---

重点:
注意!这里面最重要的就是 layout 选项,后面的参数对应的是你 主题文件夹下 layout 文件夹下第一级的布局文件。比如,我的主题是用 ejs 写的,那么对应的就是 layout/tags.ejs,如果没有,那么就会出现空白的现象!如果你的 tags 文件的命名为 tags.ejs,那么你就应该写成 layout: tags

3、编辑主题配置文件_config.yml中的menu部分

1
2
3
4
5
6
7
menu:
主页: /
归档: /archives/
分类: /categories/
标签: /tags/
#旅行: /tags/旅行/
关于: /about/

4、在博客markdown文档中的头部增加分类和标签

例如:

1
2
3
4
5
6
---
title: Hello World
categories: hexo
tags:
- hexo
---

至此,问题完美解决

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2015-2020 phyger
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信