-
Notifications
You must be signed in to change notification settings - Fork 142
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
feat: add externalLinkPrefixes support #1674
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,12 +96,10 @@ export function normalizeSlash(url: string) { | |
return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url))); | ||
} | ||
|
||
export function isExternalUrl(url = '') { | ||
export function isExternalUrl(url = '', externalLinkPrefixes?: string[]) { | ||
return ( | ||
url.startsWith('http://') || | ||
url.startsWith('https://') || | ||
url.startsWith('mailto:') || | ||
url.startsWith('tel:') | ||
/^((https?|mailto|tel):)?\/\//.test(url) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this regex is not as same as before, you can see tests failed in CI. And this regex has edge cases like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend to keep origin methods to make it more readable and easier to understand for simple checks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just take an example to show the difference. |
||
externalLinkPrefixes?.some(prefix => url.startsWith(prefix)) | ||
); | ||
} | ||
|
||
|
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.
There are some differences here.
#
is missed,#my-anchor
should not be considered as externalUrl but can be ignored in dead links check.