hexo icon indicating copy to clipboard operation
hexo copied to clipboard

The value of `data.slug` in `postPermalinkFilter` is incorrect

Open jat001 opened this issue 4 years ago • 5 comments

I moved some posts from source/_posts/ to source/_posts/archive. And I want to keep the permalink unchanged. So I changed the config from permalink: :title.html to permalink: :name.html. But it did not work.

image

It seems the value of data.slug is not correct. It should be archive/mongodb-and-mysql-compared, not archive-mongodb-and-mysql-compared. Does anyone know where data.slug comes from?

jat001 avatar Dec 12 '21 23:12 jat001

BTW, I am using Windows. Does it work on mac and Linux?

jat001 avatar Dec 12 '21 23:12 jat001

This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Feb 11 '22 00:02 github-actions[bot]

Source:

https://github.com/hexojs/hexo/blob/860f1bfb77ef8306b7d3a39a4ff8481544a15360/lib/hexo/post.js#L232 https://github.com/hexojs/hexo-util/blob/master/lib/slugize.js

stevenjoezhang avatar Feb 11 '22 04:02 stevenjoezhang

https://github.com/hexojs/hexo-util/blob/a20e69761cafca7ff02917e79c3307f86a7877b5/lib/slugize.js#L19

so why replace the slash with the hyphen?

https://github.com/hexojs/hexo/blob/860f1bfb77ef8306b7d3a39a4ff8481544a15360/lib/plugins/filter/post_permalink.js#L22

basename will not work in this situation.

jat001 avatar Feb 12 '22 02:02 jat001

BTW, slug in db.json is generated by processPost, which is used in postPermalinkFilter.

https://github.com/hexojs/hexo/blob/860f1bfb77ef8306b7d3a39a4ff8481544a15360/lib/plugins/processor/post.js#L99

https://github.com/hexojs/hexo/blob/860f1bfb77ef8306b7d3a39a4ff8481544a15360/lib/plugins/processor/post.js#L94

https://github.com/hexojs/hexo/blob/860f1bfb77ef8306b7d3a39a4ff8481544a15360/lib/plugins/processor/post.js#L213

jat001 avatar Feb 12 '22 02:02 jat001

But, permalink: :name.html should work here. name will be replaced with filename without dirname and extname.

basename(slug) may not match the expected behavior, need to check commit history.

stevenjoezhang avatar Nov 22 '22 05:11 stevenjoezhang

See https://github.com/hexojs/hexo/pull/1247

stevenjoezhang avatar Nov 22 '22 05:11 stevenjoezhang

I will close this Issue because my tests show that using ":name" achieves your expected result. If you find that ":name" is generating incorrect permanent links, please provide the blog source code that can reproduce the issue.

stevenjoezhang avatar Jul 27 '23 02:07 stevenjoezhang