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

Make external links open in a new tab by default #193

Merged
merged 8 commits into from
Sep 8, 2022

Conversation

benface
Copy link
Contributor

@benface benface commented Sep 2, 2022

This PR changes links in mdx files to automatically have target="_blank" if the href doesn't start with / or # (meaning it's an external link, and we've been following the pattern of opening external links in new tabs on thegraph.com).

@benface benface requested a review from a team as a code owner September 2, 2022 02:21
@hasparus
Copy link
Contributor

hasparus commented Sep 2, 2022

Technically, you could use two leading slashes in an external link, but I wrote isExternal = href.startsWith('http') so many times in my life that I lost the right to request changes on this PR.

https://stackoverflow.com/questions/9646407/two-forward-slashes-in-a-url-src-href-attribute

@benface
Copy link
Contributor Author

benface commented Sep 8, 2022

Technically, you could use two leading slashes in an external link

@hasparus – Super good catch, but it looks like even next/link doesn't support that. 😅 <NextLink href="//thegraph.com" passHref> renders href="/thegraph.com".

Still, looking into this made me improve/simplify the code (removed 8 lines), so thank you.

@benface benface merged commit d8e5fbe into main Sep 8, 2022
@benface benface deleted the benface/external-links-open-in-new-tab branch September 8, 2022 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants