File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import { Lang } from "../utils/languages"
1717import { trackCustomEvent , MatomoEventOptions } from "../utils/matomo"
1818import * as url from "../utils/url"
1919import { Direction } from "../types"
20+ import { SITE_URL , DISCORD_PATH } from "../constants"
2021
2122export interface IBaseProps {
2223 to ?: string
@@ -63,8 +64,10 @@ const Link: React.FC<IProps> = ({
6364
6465 // TODO: in the next PR we are going to deprecate the `to` prop and just use `href`
6566 // this is to support the ButtonLink component which uses the `to` prop
66- const to = ( toProp ?? href ) !
67+ let to = ( toProp ?? href ) !
6768
69+ const isDiscordInvite = url . isDiscordInvite ( to )
70+ if ( isDiscordInvite ) to = new URL ( DISCORD_PATH , SITE_URL ) . href
6871 const isExternal = url . isExternal ( to )
6972 const isHash = url . isHash ( to )
7073 const isGlossary = url . isGlossary ( to )
Original file line number Diff line number Diff line change 1+ export const SITE_URL = "https://ethereum.org" as const
2+ export const DISCORD_PATH = "/discord/" as const
13export const GATSBY_FUNCTIONS_PATH = process . env . GATSBY_FUNCTIONS_PATH || "/api"
24
35// Quiz Hub
Original file line number Diff line number Diff line change 1+ import { DISCORD_PATH } from "../constants"
2+
13const HASH_PATTERN = / ^ # .* /
24const isHashLink = ( href : string ) : boolean => HASH_PATTERN . test ( href )
35
6+ export const isDiscordInvite = ( href : string ) : boolean =>
7+ href . includes ( DISCORD_PATH ) && ! href . includes ( "http" )
8+
49export const isExternal = ( href : string ) : boolean =>
510 href . includes ( "http" ) || href . includes ( "mailto:" ) || href . includes ( "ipfs" )
611
You can’t perform that action at this time.
0 commit comments