永久链接¶
hexo
在_config.yml
中设置属性permalink
属性用于设置文章在静态文件生成后的路径
permalink: :year/:month/:day/:title/
permalink_defaults:
比如文章hello-world.md
的源路径为
/source/_posts/hello-world.md
生成静态文件后的路径为
/public/2019/01/23/hello-world/index.html
变量¶
hexo
提供了以下变量来生成永久链接
变量 | 描述 |
---|---|
:year | 发表年份(4位数字) |
:month | 发表月份(2位数字) |
:i_month | 发表月份(没有前置0) |
:day | 发表日(2位数字) |
:i_day | 发表日(没有前置0) |
:title | 文件名 |
:post_title | 文章标题 |
:post_title | 文章ID |
:category | 类别。如果没有分类,那么使用属性default_category的值 |
比如文章配置块内容如下:
title: Hello World
date: 2013-07-14 17:01:34
categories:
- foo
- bar
那么可以定义如下的永久链接
:year/:month/:day/:title/
:year-:month-:day-:title.html
:category/:title
生成的静态文件如下
2013/07/14/hello-world/index.html
2013-07-14-hello-world.html
foo/bar/hello-world
语言设置¶
可以使用属性permalink_defaults:
指定默认值,比如使用语言
permalink_defaults:
lang: en
hexo-abbrlink¶
参考:
插件hexo-abbrlink
支持生成更加常见的永久链接,其实现方式
对标题+时间进行md5然后再转base64,保存在front-matter中。
安装
npm install hexo-abbrlink --save
修改_config.yml
permalink: posts/:abbrlink.html
可以修改生成的算法和表示方式
算法:crc16(默认)或crc32
表示:dec(默认,十进制)或hex(十六进制)
配置方式
# abbrlink config
abbrlink:
alg: crc32 #support crc16(default) and crc32
rep: hex #support dec(default) and hex
编译后会在源文件的配置块中插入
abbrlink: xxxxx
资源文件¶
如果有使用永久链接插件hexo-abbrlink
,那么会将source/_posts
文件夹下的资源文件夹名转换成为属性值abbrlink
,所以还是使用资源文件默认方式,在source
文件夹下新建文件夹images
,将资源文件放置在其中,引用链接如下
![](/images/asset-name/file-name)