hexo基本操作

hexo 文章管理

1.增加文章

1
hexo new xx

创建的文件自动保存在source/_post文件夹下,为MarkDown格式

可以在文件中开头通过:

1
2
3
4
5
6
7
8
9
10
11
---
title: 标题 # 自动创建,如 hello-world
date: 日期 # 自动创建,如 2019-09-22 01:47:21
tags:
- 标签1
- 标签2
- 标签3
categories:
- 分类1
- 分类2
---

来添加文章的必要信息。

2.标签页添加

在项目的根目录下执行命令

1
hexo new page tags

执行命令后自动生成一个source/tags/index.md文件,内容如下:

1
2
3
4
---
title: tags
date: 2019-09-26 16:44:17
---

可以为其增加type字段指定页面的类型:

1
2
type: tags
comments: false

在使用的主题_config.yml文件将页面的链接加到主菜单中,修改menu字段:

1
2
3
4
5
6
7
8
9
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

本地服务重启,可以观察到页面状态变化(左侧导航出现标签,点击之后会显示标签的列表)。

3.分类页

对文章进行归类,一个文章可以对应某个或多个分类,可以通过以下命令创建分类页:

1
hexo new page categories

生成一个/source/categories/index.md文件。

在其中增加type字段来指定页面的类型:

1
2
type: categories 
comments: false

然后在使用的主题_config.yml文件中将页面链接加入到主菜单中,修改menu字段:

1
2
3
4
5
6
7
8
9
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

4.添加搜索页

需要搜索全站的内容,所以一个搜索功能的支持也是很有必要的,要添加搜索的支持,需要先安装一个插件,叫做 hexo-generator-searchdb,命令如下:

1
npm install hexo-generator-searchdb --save

然后在项目的_config.yml中添加搜索设置如下:

1
2
3
4
5
search:
path: search.xml
field: post
format: html
limit: 10000

然后在主题的 _config.yml 里面修改如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
# Local search
# Dependencies: https://github.com/wzpan/hexo-generator-search
local_search:
enable: true
# If auto, trigger search by changing input.
# If manual, trigger search by pressing enter key or search button.
trigger: auto
# Show top n results per article, show all results by setting to -1
top_n_per_article: 5
# Unescape html strings to the readable one.
unescape: false
# Preload the search data when the page loads.
preload: false

5.404页面添加

若需要添加一个 404 页面,直接在根目录 source 文件夹新建一个 404.md 文件,内容可以仿照如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
---
title: 404 Not Found
date: 2019-11-27 10:41:27
---

<center>
对不起,您所访问的页面不存在或者已删除。
您可以<a href="https://dongshifu.github.io>">点击此处</a>返回首页。
或访问<a href="https://blog.csdn.net/dongshifo">查看更多内容。
</center>

<blockquote class="blockquote-center">
Dongshifu
</blockquote>