Hexo建站笔记

环境准备

文档 | Hexo

建站指令

指令 | Hexo

使用主题

在 Hexo 官网的主题页面选择自己想要的主题:Themes | Hexo

对应的主题内会有使用步骤说明

使用插件

文章搜索插件

安装 npm 包:

1
npm install hexo-generator-searchdb --save

然后将以下配置复制到博客根目录下的 _config.yml 里(注意不是 ayer 目录下的):

1
2
3
4
5
# hexo-generator-searchdb
search:
path: search.xml
field: post
format: html

RSS 订阅插件

安装 npm 包:

1
npm install hexo-generator-feed --save

然后将以下配置复制到你博客根目录下的 _config.yml 里(注意不是 ayer 目录下的):

1
2
3
4
5
6
7
8
9
feed:
type: atom
path: atom.xml
limit: 20
hub:
content:
content_limit: 140
content_limit_delim: " "
order_by: -date

文章永久链接插件

Hexo 默认的静态 URL 格式是 :year/:month/:day/:title,也就是按照年、月、日、标题来生成固定链接的。如:http://xxx.yy.com/2020/07/06/hello-world

这种默认配置的缺点就是一般文件名是中文,导致 url 链接里有中文出现,这会造成很多问题(例如 md 文件名改变后,访问链接也会跟着变),也不利于 seo,另外就是年月日都会有分隔符。

安装 npm 包:

1
2
3
4
5
6
7
8
9
10
11
$ npm install hexo-abbrlink --save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ hexo-abbrlink@2.2.1
added 5 packages from 9 contributors and audited 248 packages in 5.109s

22 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities

修改 _config.yml 文件中的配置项(记得把原来的 permalink: 删除掉):

1
2
3
4
5
6
7
8
9
10
11
12
13
# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
# url: http://example.com
# permalink: :year/:month/:day/:title/
# permalink_defaults:
# pretty_urls:
# trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
# trailing_html: true # Set to false to remove trailing '.html' from permalinks
# hexo-abbrlink
permalink: blog/:abbrlink.html # 也可以直接写 :abbrlink/
abbrlink:
alg: crc32 # 算法: crc16(default) and crc32
rep: hex # 进制: dec(default) and hex

配置修改完后,需要清除掉之前已生成的网页,然后重新生成

1
2
3
4
5
6
$ hexo clean
INFO Validating config
INFO Deleted database.
INFO Deleted public folder.

$ hexo g

插件说明:

  • alg:算法(目前支持 crc16crc32 算法,默认值是 crc16
  • rep:形式(生成的链接可以是十六进制格式也可以是十进制格式,默认值是十进制格式)

生成链接样式:

1
2
3
4
5
6
7
8
9
10
11
# crc16 & hex
https://post.zz173.com/posts/66c8.html

# crc16 & dec
https://post.zz173.com/posts/65535.html

# crc32 & hex
https://post.zz173.com/posts/8ddf18fb.html

# crc32 & dec
https://post.zz173.com/posts/1690090958.html

undefined

如果出现 undefined 的情况,

  1. 检查是否已经执行 hexo clean
  2. 检查 package.json 文件,看看是否已安装 hexo-abbrlink 插件





  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2022-2024 Liangxj
  • 访问人数: | 浏览次数: