Skip to content
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(postPermalinkFilter): permalink_defaults should not overwrite values #3926

Merged
merged 1 commit into from Dec 11, 2019

Conversation

@dailyrandomphoto
Copy link
Member

dailyrandomphoto commented Dec 10, 2019

What does it do?

permalink_defaults option does not work correctly from 4.1.0.
According https://hexo.io/docs/permalinks, set _config.yml as

permalink: :lang/:title/
permalink_defaults:
  lang: en
$ hexo new "Hello World" --lang tw

and the URL will be:

# expected is
http://localhost:4000/tw/hello-world/

# but actual is 
http://localhost:4000/en/hello-world/

Compare v4.0.0 and v4.1.0,
I found the related change is e0f2478#diff-dbb03cb234189f8e709e7c5f9921aa67L45 (#3790)

- return permalink.stringify(defaults(meta, config.permalink_defaults));
+ return permalink.stringify(Object.assign(meta, config.permalink_defaults));

If change to

Object.assign([], config.permalink_defaults, meta)

it causes "Maximum call stack size exceeded" error, so use for loop to copy values.

How to test

git clone -b fix-permalinkDefaults https://github.com/dailyrandomphoto/hexo.git
cd hexo
npm install
npm test

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.
@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 10, 2019

Coverage Status

Coverage increased (+0.004%) to 97.135% when pulling 2e8ec74 on dailyrandomphoto:fix-permalinkDefaults into c19096b on hexojs:master.

1 similar comment
@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 10, 2019

Coverage Status

Coverage increased (+0.004%) to 97.135% when pulling 2e8ec74 on dailyrandomphoto:fix-permalinkDefaults into c19096b on hexojs:master.

@curbengh curbengh added this to the 4.1.1 milestone Dec 11, 2019
@@ -6,18 +6,19 @@ let permalink;

function postPermalinkFilter(data) {
const { config } = this;
const { id, _id, slug, title, date } = data;

This comment has been minimized.

Copy link
@curbengh

curbengh Dec 11, 2019

Contributor

👍

Copy link
Contributor

curbengh left a comment

Verified on a test blog.

for (const key of keys2) {
if (Object.prototype.hasOwnProperty.call(meta, key)) continue;

meta[key] = config.permalink_defaults[key];

This comment has been minimized.

Copy link
@SukkaW

SukkaW Dec 11, 2019

Member

Try deepMerge() to see if Maximum call stack size exceeded still occurs.


Update

According to the documents of lodash.defaults:

Source objects are applied from left to right. Once a property is set, additional values of the same property are ignored.

Yeah, it is my mistake to replace lodash.defaults with Object.assign.

@SukkaW
SukkaW approved these changes Dec 11, 2019
@SukkaW SukkaW merged commit 2796894 into hexojs:master Dec 11, 2019
4 checks passed
4 checks passed
Travis CI - Pull Request Build Passed
Details
codeclimate All good!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
coverage/coveralls Coverage increased (+0.004%) to 97.135%
Details
@curbengh curbengh mentioned this pull request Dec 11, 2019
1 of 2 tasks complete
@SukkaW SukkaW mentioned this pull request Dec 12, 2019
1 of 1 task complete
oncletom added a commit to oncletom/hexo that referenced this pull request Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.