-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(#3464): override permalink use the front-matter #4359
Conversation
@@ -121,7 +121,7 @@ module.exports = ctx => { | |||
} | |||
|
|||
if (data.permalink) { | |||
data.slug = data.permalink; | |||
data.__permalink = data.permalink; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BREAKING CHANGES.
data.slug
won't be override by data.permalink
. That means data.slug
will still come from the original path relative to source/_posts
.
Also, a new __permalink
is created to avoid overriding Post.virtual('permalink').get
.
if (__permalink) { | ||
if (!__permalink.startsWith('/')) return `/${__permalink}`; | ||
return __permalink; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a __permalink
is detected (which is added by post processor from permalink
inside the front-matter), it will be return directly.
BREAKING CHANGES:
permalink
inside the front-matter is no longer controlled by hexo.config.permalink
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WFM. One thing to note that is that hexo-server currently needs a trailing slash in permalink:
(regardless of _config.yml
or front-matter), otherwise it responds with invalid mime type; this limitation could be resolved in hexojs/hexo-server#111.
What does it do?
The PR closes #1158, closes #1813, closes #3464
#3464 (comment)
hexo/lib/plugins/processor/post.js
Lines 123 to 126 in edef5c2
Originally, during the processing of the post, the
permalink
defined in the front-matter which isdata.permalink
, will overridedata.slug
anddata.permalink
will be deleted.And, in
post_permalink
filter,data.slug
will be used to getname
andtitle
property:hexo/lib/plugins/filter/post_permalink.js
Lines 15 to 16 in edef5c2
So if I got a post:
source/_posts/i-love-hexo/hello.md
, I will get:i-love-hexo/hello
hello
If I then defines
permalink
aspermalink-test/hi.md
, I will get:permalink-test/hi
hi
.I don't know why it is designed like this. Maybe using the
permalink
to override the relative path undersource/_posts
. But it doesn't make any sense - why I have to override the relative path? I could just create required directories undersource/_posts
and it will be fine.Also, the behavior of
Post
is different fromPage
, whichpermalink
in the front-matter is truly able to override thehexo.config.permalink
. And that behavior is what user really want.So in this PR, I made a few changes toward post processor and
post_permalink
filter.As the behavior of the
permalink
in the front-matter has changed, thus the PR is still considered as a Breaking ChangeHow to test
Screenshots
Pull request tasks