next主题自定义页面配置

Next 允许用户在菜单中添加自定义页面。

  • 添加新页面 →

  • 设置前置事项值 →

  • 编辑菜单

在终端中切换到站点根目录。使用 hexo new page custom-name  命令创建一个名为 custom-name  的新页面:

1
2
3
4
5
6
cd hexo-site
hexo new page custom-name
```

前置事项(Front-matter)是文件开头的一块 YAML 或 JSON 格式的内容,用于配置文章的设置。更多关于前置事项的设置可以在 
Front-matter 文档  中找到。如果你愿意,也可以在 custom-name/index.md  中添加内容。

title: custom-name
date: 2014-12-22 12:39:04

1
2
3
4
  
通过编辑 NexT 配置文件,将 custom-name  添加到 menu  中,就像添加 about  页面一样:

NexT 配置文件:

menu:
  home: / || fa fa-home
  archives: /archives/ || fa fa-archive
  about: /about/ || fa fa-user

1
2
3
4
5
6
7
8
9
10
11
  
如果你想要添加标签或分类页面,请继续阅读。

请阅读 Hexo 的  分类与标签文档  来了解如何为文章添加标签或分类。

以下是一个带有标签的文章示例:
### 将归档页面设置为首页

你可以在 Hexo 配置文件中配置归档和索引生成器的路径,例如:

Hexo 配置文件:

archive_dir: /

index_generator:
  path: archives
  per_page: 10
  order_by: -date

1
2
3
4
5
6
7
8
9
10
### 添加「标签」页面  

添加「标签」页面,并在菜单中显示「标签」链接。「标签」页面将显示站点的所有标签。如果没有文章带有标签,该页面将为空白。
- 添加新页面 →

- 设置页面类型 →

- 编辑菜单

在终端中切换到站点根目录。使用 hexo new page tags  命令创建一个名为 tags  的新页面:

cd hexo-site
hexo new page tags

1
2
  
编辑新页面,并将类型更改为 tags ,主题将自动在该页面显示标签云。页面内容如下所示:

title: Tags
date: 2014-12-22 12:39:04
type: tags

1
2
3
4
  
通过编辑 NexT 配置文件,将 tags  添加到 menu  中,如下所示:

NexT 配置文件:

menu:
  home: / || fa fa-home
  archives: /archives/ || fa fa-archive
  tags: /tags/ || fa fa-tags

1
2
3
4
5
6
7
8
  
如果你为站点启用了任何评论系统,评论将显示在所有文章和页面上。

如果你想要为像 tags  或 categories  这样的页面禁用评论,请查看「如何在页面上禁用评论」。

默认情况下,Hexo 插件 hexo-generator-tag  提供了一个名为 enable_index_page  的选项,这将与上面创建的「标签」页面冲突。请确保你已禁用该选项。

Hexo 配置文件:

tag_generator:
  enable_index_page: false

1
2
3
4
5
#### 标签云  

NexT v7.0.2 开始,你可以自定义标签云的颜色、大小等属性,只需在 NexT 配置文件中设置相关值:

NexT 配置文件:

tagcloud:
  min: 12
  max: 30
  amount: 200
  orderby: name
  order: 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
### 添加「分类」页面  

添加「分类」页面的方法与添加「标签」页面类似,唯一的区别是名称不同:只需将 tags  替换为 categories  即可。
### 添加谷歌日历页面

请注意,你首先需要添加一个设置为公开的谷歌日历。如果你不确定如何操作,请先按照以下说明将谷歌日历设置为公开,然后再添加。

关于创建和管理公开谷歌日历的详细文档,请访问: https://support.google.com/calendar/answer/37083
- 设置谷歌日历 →

- 添加日程页面 →

- 设置页面类型 →

- 编辑菜单

- 获取日历 ID 和 API 密钥 →

- NexT 配置

你可以通过在 calendar  部分设置值来启用该功能。将日历 ID 和 API 密钥的值复制到 NexT 配置文件中。

NexT 配置文件:

calendar:
calendar_id: 
api_key: 
orderBy: startTime
showLocation:false
offsetMax:72
offsetMin:4
showDeleted:false
singleEvents:true
maxResults:250

1
2
  
在终端中切换到站点根目录。使用 hexo new page schedule  命令创建一个名为 schedule  的新页面:

cd hexo-site
hexo new page schedule

1
2
  
编辑新页面,并将类型更改为 schedule ,主题将自动在该页面显示日程。页面内容如下所示:

title: Schedule
date: 2014-12-22 12:39:04
type: schedule

1
2
3
4
  
通过编辑 NexT 配置文件,将 schedule 添加到 menu  中:

NexT 配置文件:

menu:
  home: / || fa fa-home
  archives: /archives/ || fa fa-archive
  schedule: /schedule/ || fa fa-calendar

1
2
3
### 自定义 404 页面  

在终端中切换到站点根目录的 source  文件夹。创建一个名为 404  的新文件夹,然后在其中创建一个新页面:

cd hexo-site
hexo new page 404

1
2
3
4
  
请确保在 Hexo 配置文件中禁用了 relative_link :

Hexo 配置文件:

relative_link: false

1
2
3
4
5
  
用户是否能够被重定向到 404 页面取决于网站托管服务或 Web 服务器的设置,而不是 Hexo。例如,如果你使用 Nginx 作为服务器,你还需要在 nginx.conf  文件中配置 404 页面。
#### 公益 404

如果你想要启用「公益 404」(腾讯在中国提供的服务),请按照以下方式编辑 404/index.md :

—title: ‘404’
date: 2014-12-22 12:39:04
comments: false

1
2
3
4
5
6
  
你也可以在其中添加任何你想要的内容。

通过编辑 NexT 配置文件,将 404  添加到 menu  中:

NexT 配置文件:

menu:
  home: / || fa fa-home
  archives: /archives/ || fa fa-archive
  commonweal: /404/ || fa fa-heartbeat

  
  

![江达小记](/images/wechatmpscan.png)