Hexo Change Permanent Link Format With Backward Compatibility
Hexo Change Permanent Link Format
Recently I would like to simplify permanent link for each post. From:
/2020/09/12/deploy-docker-on-ubuntu18-04
/2022/12/15/abplearn/sixth
To:
/deploy-docker-on-ubuntu18-04
/abplearn/sixth
If you don’t care about the search engine drop right after directly changing the permalink, you can change the config in _config.yml
,change permalink
from :year/:month/:day/:title/
to :title/
directly. otherwise, please read on.
install sitemap generate to generate sitemap.txt
1 | yarn add hexo-generator-sitemap |
add or change config in _config.yml
to get sitemap.txt
1 | sitemap: |
after then , run hexo g
to generate the sitemap.txt.
run python script to create html for 301
1 | import os |
you can run this script on your pc,but change necessary params on top of the script
Skip Render 301 Files
Change the config in _config.yml
, for skip render those html files for 301
1 | skip_render: |
Generate New File
Now , you can change permalink .
Change the config in _config.yml
,change permalink
from :year/:month/:day/:title/
to :title/
.
Run hexo g -d
to generate new file and upload those to github.
Remove the created static file
up to one year later , or maybe half a year , those files will not be needed anymore ,please delete them directly.