-
-
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 to use root to export Permalink #3604
Conversation
1 similar comment
Codeclimate is not passed, but it was so before I touched it. Please check. |
Sorry, We have many repositories and need to maintain them. |
It's used in several tag plugins like include code to link to a local path via hexo/lib/plugins/tag/include_code.js Line 59 in da14a16
Post model replace the config.root with '/', Line 57 in f172774
The above works because the docs requires root value in both url and root. Alternatively, we can specify just one root value: url: http://example.com
root: /blog/ The issue with this approach is that I'm not so worry about the breaking change of the above approach, since v4 is on the horizon. @yoshinorin |
Currently the config requires root value in both url and root, For example, url: http://yoursite.com/child
root: /child/ then return `${ctx.config.url}${ctx.config.root}${this.path}`; will return |
@weyusi
Lines 32 to 33 in f172774
I think almost certainly this PR is okay. I'm going to approve and merge this PR. But, I'm not yet completed check current hexo source code. So, I haven't got confirmation of that yet. |
@yoshinorin config.root.replace(/\/*$/, '/'); this make sure the value ends with a slash, '/child' -> '/child/' config.url.replace(/\/+$/, ''); this make sure the url does not ends with a slash,
Anyhow, 'child' value is still there. I just tested this PR and it definitely results in For this PR to work, '/child' needs to be removed from config.url (either ask user to update their _config.yml or programmatically via load_config.js). |
@weyusi NOTE: I do not confirm it on the current master source code. Just confirmed on a console. Current hexo config & result
My understanding its means... Pattern 1: OKSettings url: http://yoursite.com
root: / Result const urlOne = "http://example.com".replace(/\/+$/, '');
const rootOne = "/".replace(/\/*$/, '/');
console.log('urlOne: ' + urlOne);
console.log('rootOne: ' + rootOne);
console.log('pattern1: ' + urlOne + rootOne + "\n");
// Result
urlOne: http://example.com
rootOne: /
pattern1: http://example.com/ Pattern 2: OKSettings url: http://yoursite.com
root: /child Result const urlTwo = "http://example.com".replace(/\/+$/, '');
const rootTwo = "/child".replace(/\/*$/, '/');
console.log('urlTwo: ' + urlTwo);
console.log('rootTwo: ' + rootTwo);
console.log('pattern2: ' + urlTwo + rootTwo + "\n");
// Result
urlTwo: http://example.com
rootTwo: /child/
pattern2: http://example.com/child/ Pattern 3: OKSettings url: http://yoursite.com/
root: /child Result const urlThree = "http://yoursite.com/".replace(/\/+$/, '');
const rootThree = "/child".replace(/\/*$/, '/');
console.log('urlThree: ' + urlThree);
console.log('rootThree: ' + rootThree);
console.log('pattern3: ' + urlThree + rootThree + "\n");
// Result
urlThree: http://yoursite.com
rootThree: /child/
pattern3: http://yoursite.com/child/ Pattern 4: NGSettings url: http://yoursite.com/
root: child Result const urlFour = "http://yoursite.com/".replace(/\/+$/, '');
const rootFour = "child".replace(/\/*$/, '/');
console.log('urlFour: ' + urlFour);
console.log('rootFour: ' + rootThree);
console.log('pattern4: ' + urlFour + rootFour + "\n");
// Result
urlFour: http://yoursite.com
rootFour: /child/
pattern4: http://yoursite.comchild/ <- it's wrong. But not relate this PR My understanding is above. Is it okay?? About this PRThis PR is not change So, I think maybe this PR is not breaking change & merge safely. How do you think? :) |
is the current approach. While I don't necessarily agree with that approach, unless the current approach is updated, this PR is a breaking change. My suggestion is to switch to the following approach (a breaking change),
Then change, Line 33 in f172774
to config.url = config.url.replace(/\/+$/, '').concat(config.root); This will also fix #3601, without this PR. |
Maybe @sKawashima @yoshinorin haven't realize, url: http://yoursite.com/child
root: /child/ which is (I iterate again) the current approach. I understand @sKawashima might not like that approach, me neither. Most users either has "/" as The rationale of using If user wants to use, url: http://yoursite.com/
root: /child/ without using config.url = config.url.replace(/\/+$/, '').concat(config.root); in hexo/lib/hexo/load_config.js. So, the real question is, should url: http://yoursite.com/child
root: /child/ be deprecated, in favor of url: http://yoursite.com/
root: /child/ ? |
@weyusi I have tried it once, but I sent this PR because I had a few problems. I think that it is not consistent about url extraction of |
@weyusi @sKawashima url: http://yoursite.com/
root: /child/ Sorry for the confusion... |
Good question, url: http://yoursite.com/child
root: /child/ and your page is located at
As for the purpose of Instead of using permalink which results in If you can pinpoint the exact issue (e.g. expected urls vs actual urls), it can help us to troubleshoot. |
I'm sorry for the late reply. |
What does it do?
Fix to use root to export permalink.
It fix #3601 .
How to test