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

refactor(isExternal): avoid undefined & improve performance #124

Merged
merged 6 commits into from Nov 17, 2019

Conversation

@SukkaW
Copy link
Member

SukkaW commented Nov 8, 2019

The PR fixes #123 with a simpler way. This PR also includes the changes from hexojs/hexo#3839 , which is a poc of performance improvements.

@SukkaW SukkaW requested a review from curbengh Nov 8, 2019
@coveralls

This comment has been minimized.

Copy link

coveralls commented Nov 8, 2019

Coverage Status

Coverage decreased (-0.09%) to 95.364% when pulling 6ea2fb7 on SukkaW:perf-is-external into 71bbcc4 on hexojs:master.

@SukkaW SukkaW added this to In progress in Drop legacy URL API via automation Nov 8, 2019
@SukkaW SukkaW removed this from In progress in Drop legacy URL API Nov 8, 2019
const host = data.hostname;
const sitehost = typeof urlObj(config.url) === 'object' ? urlObj(config.url).hostname : config.url;
const sitehost = parse(config.url).hostname || config.url;
// Pass a base to new URL

This comment has been minimized.

Copy link
@curbengh

curbengh Nov 9, 2019

Contributor

I would say the purpose is // Relative url handling.

This comment has been minimized.

Copy link
@SukkaW

SukkaW Nov 9, 2019

Author Member

Updated to // handle relative url since there is a handle mailto: javascript: vbscript: and so on below.

const sitehost = typeof urlObj(config.url) === 'object' ? urlObj(config.url).hostname : config.url;
const sitehost = parse(config.url).hostname || config.url;
// Pass a base to new URL
const data = new URL(url, `http://${sitehost}`);

if (!sitehost || typeof data === 'string') return false;

This comment has been minimized.

Copy link
@curbengh

curbengh Nov 9, 2019

Contributor

with L15, typeof data is no longer required since it will always be an "object".

This comment has been minimized.

Copy link
@SukkaW

SukkaW Nov 9, 2019

Author Member

Removed.

@@ -18,17 +10,19 @@ const urlObj = (str) => {

function isExternalLink(url) {

This comment has been minimized.

Copy link
@curbengh

curbengh Nov 9, 2019

Contributor

suggest to rename to path or input to not confuse with new URL().

This comment has been minimized.

Copy link
@SukkaW

SukkaW Nov 9, 2019

Author Member

input might be a good idea.

SukkaW added 2 commits Nov 9, 2019
Apply suggestions from code review by @curbengh
@curbengh

This comment has been minimized.

Copy link
Contributor

curbengh commented Nov 9, 2019

It's fine to use isExternalLink(url) in documentation.

@curbengh curbengh dismissed their stale review Nov 9, 2019

handling null config.url

@SukkaW

This comment has been minimized.

Copy link
Member Author

SukkaW commented Nov 9, 2019

@curbengh So should we should throw a TypeError if config.url is null or undefined?

@SukkaW SukkaW requested a review from curbengh Nov 13, 2019
@curbengh curbengh merged commit e2e3739 into hexojs:master Nov 17, 2019
2 of 3 checks passed
2 of 3 checks passed
coverage/coveralls Coverage decreased (-0.09%) to 95.364%
Details
Travis CI - Pull Request Build Passed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.