Skip to content

Commit 196ded0

Browse files
authored
Merge pull request #10397 from ethereum/discord-invite
Force /discord/ invite path links to full url
2 parents b28dac2 + cf904d4 commit 196ded0

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/components/Link.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Lang } from "../utils/languages"
1717
import { trackCustomEvent, MatomoEventOptions } from "../utils/matomo"
1818
import * as url from "../utils/url"
1919
import { Direction } from "../types"
20+
import { SITE_URL, DISCORD_PATH } from "../constants"
2021

2122
export 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)

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export const SITE_URL = "https://ethereum.org" as const
2+
export const DISCORD_PATH = "/discord/" as const
13
export const GATSBY_FUNCTIONS_PATH = process.env.GATSBY_FUNCTIONS_PATH || "/api"
24

35
// Quiz Hub

src/utils/url.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import { DISCORD_PATH } from "../constants"
2+
13
const HASH_PATTERN = /^#.*/
24
const 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+
49
export const isExternal = (href: string): boolean =>
510
href.includes("http") || href.includes("mailto:") || href.includes("ipfs")
611

0 commit comments

Comments
 (0)