hexo生成html永久链接
一、使用
1.Hexo
在_config.yml
中设置属性permalink
属性用于设置文章在静态文件生成后的路径
permalink: :year/:month/:day/:title/
permalink_defaults:
2.比如文章hello-world.md
的源路径为
/source/_posts/hello-world.md
3.生成静态文件后的路径为
/path/to/public/2021/03/10/hello-world/index.html
二、变量
1.Hexo
提供了以下变量来生成永久链接
变量 | 描述 |
---|---|
:year | 发表年份(4位数字) |
:month | 发表月份(2位数字) |
:i_month | 发表月份(没有前置0) |
:day | 发表日(2位数字) |
:i_day | 发表日(没有前置0) |
:title | 文件名 |
:post_title | 文章标题 |
:post_title | 文章ID |
:category | 类别。如果没有分类,那么使用属性default_category的值 |
2.比如文章配置块内容如下:
title: Hello World
date: 2013-07-14 17:01:34
categories:
- foo
- bar
3.那么可以定义如下的永久链接
:year/:month/:day/:title/
:year-:month-:day-:title.html
:category/:title
4.生成的静态文件如下
2013/07/14/hello-world/index.html
2013-07-14-hello-world.html
foo/bar/hello-world
三、语言设置
1.可以使用属性permalink_defaults:
指定默认值,比如使用语言
permalink_defaults:
lang: en
四、hexo-abbrlink (优先选择这个)
插件rozbo/hexo-abbrlink支持生成更加常见的永久链接,其实现方式
对标题+时间进行md5然后再转base64,保存在front-matter中。
1.安装
npm install hexo-abbrlink --save
2.修改_config.yml
permalink: posts/:abbrlink.html
3.可以修改生成的算法和表示方式
算法:crc16(默认)或crc32
表示:dec(默认,十进制)或hex(十六进制)
4.配置方式
# abbrlink config
abbrlink:
alg: crc32 #support crc16(default) and crc32
rep: hex #support dec(default) and hex
5.编译后会在源文件的配置块中插入
abbrlink: xxxxx
评论区