Basic tutorial

1. Problems to be optimized

The default article permalink format used by Hexo is:

year/:month/:day/:title/
Copy the code

This kind of link, if met with a Chinese title, would explode, as follows:

And this Kind of Chinese link, due to the coding problem, when sharing the article link, often become:

Just asking if you feel bad?

Not only does this result in very long links, but if you change the post date or title, the links will immediately break, resulting in a large number of dead links, so:

You’re gonna keep it for New Year’s?

The abbrlink plugin can help us solve this problem. Github repository is as follows:

2. Install abbrLink plug-in

Install the plugin in the blog root directory (where the hexo command is executed) :

npm install hexo-abbrlink --save
Copy the code

3. Edit the site configuration file

Open the site configuration file _config.yml in the root directory of the blog and modify the following configuration:

#permalink: :year/:month/:day/:title/
#permalink_defaults:
permalink: posts/:abbrlink/
abbrlink:
  alg: crc32 #support crc16(default) and crc32
  rep: dec   #support dec(default) and hex
Copy the code

Here is an explanation:

First, specify the format of the Hexo article permalink. The next two are the Settings for the ABbrLink plugin:

alg -- Algorithm (currently support crc16 and crc32, which crc16 is default)
rep -- Represent (the generated link could be presented in hex or dec value)
Copy the code

Examples of these two Settings are as follows:

crc16 & hex
https://post.zz173.com/posts/66c8.html

crc16 & dec
https://post.zz173.com/posts/65535.html
Copy the code
crc32 & hex
https://post.zz173.com/posts/8ddf18fb.html

crc32 & dec
https://post.zz173.com/posts/1690090958.html
Copy the code

4. Generate the deployment again

Regenerating the blog with Hexo Clean && Hexo G, you can see the automatically generated ABBRLink number in the blog source file:

Next use hexo D to deploy and use a browser to view:

The advantages of this optimization are as follows:

  • As long as abBRlink number unchanged, the URL of the article is unchanged, you can modify the file name, the title of the article;
  • Pure English and digital links are great for SEO;