自定义文章 URL

先说说中文转义 URL 的方式,首先需要修改 hexo 根目录下的_config.yml 文件,

1
2
3
4
#permalink: :year/:month/:title/
permalink: :year/:month/:urlname.html
permalink_defaults:
urlname: index

将原永久链接 permalink 中的 :title 替换为 urlname.html ,同时在 permalink_defaults 增加 urlname 属性,这样就可以通过在文章内容的 Formatter 配置文章的 URL 链接地址,笔者之前修改过一次永久链接格式,只保留了标题即:permalink: :title.html,现在修改为了 permalink: :urlname.html ,本文文章配置如下图,

img

本文最终的 URL 地址就是:http://cato.eu.org/hexo-custom-article-url.html

修改文章模板

修改 post.md

1
2
3
4
5
6
7
8
9
10
11
12
13
---
title: {{ title }}
date: {{ date }}
urlname:
updated:
tags:
- 1
categories:
- 2
keywords:
description:
cover:
---

这样通过命令 hexo new xxxxxx命令新建的博客文章中就自动带有这个属性。