-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Conversation
lib/is_external_link.js
Outdated
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 |
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.
I would say the purpose is // Relative url handling
.
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.
Updated to // handle relative url
since there is a handle mailto: javascript: vbscript: and so on
below.
lib/is_external_link.js
Outdated
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; |
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.
with L15, typeof data
is no longer required since it will always be an "object".
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.
Removed.
lib/is_external_link.js
Outdated
@@ -18,17 +10,19 @@ const urlObj = (str) => { | |||
|
|||
function isExternalLink(url) { |
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.
suggest to rename to path
or input
to not confuse with new URL()
.
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.
input
might be a good idea.
Apply suggestions from code review by @curbengh
It's fine to use |
@curbengh So should we should throw a TypeError if |
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.