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

feat: add externalLinkPrefixes support #1674

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JounQin
Copy link
Contributor

@JounQin JounQin commented Dec 17, 2024

Summary

Related Issue

close #1673

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

I'd like to add related tests and document if this proposal is accepted.

Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for aquamarine-blini-95325f ready!

Name Link
🔨 Latest commit 8dfe3d5
🔍 Latest deploy log https://app.netlify.com/sites/aquamarine-blini-95325f/deploys/67618c64f6a2cd0008063ff0
😎 Deploy Preview https://deploy-preview-1674--aquamarine-blini-95325f.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 79 (🔴 down 6 from production)
Accessibility: 97 (no change from production)
Best Practices: 92 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@Timeless0911 Timeless0911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write docs about this config and add more unit test for isExternalUrl function as well as new e2e test for this case with checkDeadLinks enabled?

@@ -22,7 +20,7 @@ export function checkLinks(
) {
const errorInfos: string[] = [];
links
.filter(link => !IGNORE_REGEXP.test(link))
.filter(link => !isExternalUrl(link, routeService.externalLinkPrefixes))
Copy link
Collaborator

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.

url.startsWith('https://') ||
url.startsWith('mailto:') ||
url.startsWith('tel:')
/^((https?|mailto|tel):)?\/\//.test(url) ||
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 //www.example.com and for long urls, the performance is not very good for long and complex urls.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//www.example.com should not be considered as external?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just take an example to show the difference.

@JounQin
Copy link
Contributor Author

JounQin commented Dec 18, 2024

Can you write docs about this config and add more unit test for isExternalUrl function as well as new e2e test for this case with checkDeadLinks enabled?

Sure, current PR is only basic proposal, I'll update rest part after you agree with this approach.

@Timeless0911
Copy link
Collaborator

Sure, current PR is only basic proposal, I'll update rest part after you agree with this approach.

@SoonIter Do you have any suggestions for approach to solve this issue?

@JounQin
Copy link
Contributor Author

JounQin commented Dec 18, 2024

Another case is maybe we can support dynamic external link patterns?

@SoonIter
Copy link
Member

@SoonIter Do you have any suggestions for approach to solve this issue?

not much, I think externalLinkPrefixes should be externalLinkIncludes and receiving RegExp[] maybe more flexible

@JounQin
Copy link
Contributor Author

JounQin commented Dec 18, 2024

I'll change to use RegExp instead then. But naming externalLinkPatterns maybe?

@SoonIter
Copy link
Member

I'll change to use RegExp instead then. But naming externalLinkPatterns maybe?

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Add ability to handle same-origin external links
3 participants