Skip to content

Commit 69b754e

Browse files
authored
Merge pull request #11021 from ethereum/md-links
Markdown links component
2 parents 1ba795d + 4984e24 commit 69b754e

File tree

9 files changed

+54
-15
lines changed

9 files changed

+54
-15
lines changed

src/components/MdLink.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React, { ReactNode } from "react"
2+
3+
import GlossaryTooltip from "./Glossary/GlossaryTooltip"
4+
import InlineLink from "./Link"
5+
6+
interface Props {
7+
href: string
8+
children: ReactNode
9+
}
10+
11+
/**
12+
* Link component to use in markdown templates.
13+
*
14+
* In case the `href` for the given link points to the glossary page, it
15+
* displays the GlossaryTooltip component instead of a Link.
16+
*
17+
* NOTE: This component exists because we want to keep using the link syntax
18+
* inside of our MD files. The native link syntax has a better UX with Crowdin
19+
* translations.
20+
*/
21+
function MdLink(props: Props) {
22+
const regex = new RegExp(/\/glossary\/#(.+)/)
23+
const matches = props.href.match(regex)
24+
25+
// get the `termKey` from the `href`
26+
// e.g. in `/glossary/#new-term` => "new-term" is the `termKey`
27+
if (matches?.length) {
28+
const termKey = matches[1]
29+
30+
return <GlossaryTooltip termKey={termKey} children={props.children} />
31+
}
32+
33+
return <InlineLink {...props} />
34+
}
35+
36+
export default MdLink

src/pages-conditional/dapps.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import PageMetadata from "../components/PageMetadata"
4040
import ProductList from "../components/ProductList"
4141
import PageHero from "../components/PageHero"
4242
import FeedbackCard from "../components/FeedbackCard"
43+
import GlossaryTooltip from "../components/Glossary/GlossaryTooltip"
4344

4445
import { getImage, getSrc } from "../utils/image"
4546
import { trackCustomEvent } from "../utils/matomo"
@@ -1263,9 +1264,9 @@ const DappsPage = ({
12631264
</StyledH2>
12641265
<Text>
12651266
<Translation id="page-dapps-get-started-subtitle" />{" "}
1266-
<InlineLink to="/glossary/#transaction-fee">
1267+
<GlossaryTooltip termKey="transaction-fee">
12671268
<Translation id="transaction-fees" />
1268-
</InlineLink>
1269+
</GlossaryTooltip>
12691270
</Text>
12701271
<Row>
12711272
<StepBoxContainer>

src/templates/docs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import CrowdinContributors from "../components/FileContributorsCrowdin"
3030
import GitHubContributors from "../components/FileContributorsGitHub"
3131
import GlossaryTooltip from "../components/Glossary/GlossaryTooltip"
3232
import InfoBanner from "../components/InfoBanner"
33-
import InlineLink from "../components/Link"
3433
import { mdxTableComponents } from "../components/Table"
3534
import PageMetadata from "../components/PageMetadata"
3635
import TableOfContents, {
@@ -43,6 +42,7 @@ import DocsNav from "../components/DocsNav"
4342
import DeveloperDocsLinks from "../components/DeveloperDocsLinks"
4443
import RollupProductDevDoc from "../components/RollupProductDevDoc"
4544
import YouTube from "../components/YouTube"
45+
import MdLink from "../components/MdLink"
4646

4747
import { isLangRightToLeft } from "../utils/translations"
4848
import { Lang } from "../utils/languages"
@@ -193,7 +193,7 @@ const BackToTop = (props: ChildOnlyProp) => (
193193
// Note: you must pass components to MDXProvider in order to render them in markdown files
194194
// https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#mdxprovider
195195
const components = {
196-
a: InlineLink,
196+
a: MdLink,
197197
h1: H1,
198198
h2: H2,
199199
h3: H3,

src/templates/roadmap.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import DocLink from "../components/DocLink"
2626
import Contributors from "../components/Contributors"
2727
import InfoBanner from "../components/InfoBanner"
2828
import UpgradeStatus from "../components/UpgradeStatus"
29-
import InlineLink from "../components/Link"
3029
import { mdxTableComponents } from "../components/Table"
3130
import Logo from "../components/Logo"
3231
import MeetupList from "../components/MeetupList"
@@ -45,6 +44,7 @@ import Breadcrumbs from "../components/Breadcrumbs"
4544
import RoadmapActionCard from "../components/Roadmap/RoadmapActionCard"
4645
import RoadmapImageContent from "../components/Roadmap/RoadmapImageContent"
4746
import GlossaryTooltip from "../components/Glossary/GlossaryTooltip"
47+
import MdLink from "../components/MdLink"
4848
import {
4949
Page,
5050
InfoColumn,
@@ -118,7 +118,7 @@ const TitleCard = (props: ChildOnlyProp) => (
118118
// Note: you must pass components to MDXProvider in order to render them in markdown files
119119
// https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#mdxprovider
120120
const components = {
121-
a: InlineLink,
121+
a: MdLink,
122122
h1: H1,
123123
h2: H2,
124124
h3: H3,

src/templates/staking.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import DocLink from "../components/DocLink"
2727
import Contributors from "../components/Contributors"
2828
import InfoBanner from "../components/InfoBanner"
2929
import UpgradeStatus from "../components/UpgradeStatus"
30-
import InlineLink from "../components/Link"
3130
import { mdxTableComponents } from "../components/Table"
3231
import Logo from "../components/Logo"
3332
import MeetupList from "../components/MeetupList"
@@ -54,6 +53,7 @@ import WithdrawalCredentials from "../components/Staking/WithdrawalCredentials"
5453
import WithdrawalsTabComparison from "../components/Staking/WithdrawalsTabComparison"
5554
import Callout from "../components/Callout"
5655
import GlossaryTooltip from "../components/Glossary/GlossaryTooltip"
56+
import MdLink from "../components/MdLink"
5757

5858
import { isLangRightToLeft, TranslationKey } from "../utils/translations"
5959
import { Lang } from "../utils/languages"
@@ -287,7 +287,7 @@ const TableContainer = (props: BoxProps) => (
287287
// Note: you must pass components to MDXProvider in order to render them in markdown files
288288
// https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#mdxprovider
289289
const components = {
290-
a: InlineLink,
290+
a: MdLink,
291291
h1: Header1,
292292
h2: H2,
293293
h3: H3,

src/templates/static.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import QuizWidget from "../components/Quiz/QuizWidget"
4747
import { Item as ItemTableOfContents } from "../components/TableOfContents/utils"
4848
import GlossaryDefinition from "../components/Glossary/GlossaryDefinition"
4949
import GlossaryTooltip from "../components/Glossary/GlossaryTooltip"
50+
import MdLink from "../components/MdLink"
5051

5152
import { getLocaleTimestamp } from "../utils/time"
5253
import { isLangRightToLeft, TranslationKey } from "../utils/translations"
@@ -171,7 +172,7 @@ const CardContainer = (props: ChildOnlyProp) => (
171172
// Note: you must pass components to MDXProvider in order to render them in markdown files
172173
// https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#mdxprovider
173174
const components = {
174-
a: InlineLink,
175+
a: MdLink,
175176
h1: Header1,
176177
h2: Header2,
177178
h3: Header3,

src/templates/tutorial.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ import ButtonLink from "../components/ButtonLink"
2020
import Card from "../components/Card"
2121
import Codeblock from "../components/Codeblock"
2222
import TutorialMetadata from "../components/TutorialMetadata"
23-
import FileContributors from "../components/FileContributors"
2423
import InfoBanner from "../components/InfoBanner"
2524
import EnvWarningBanner from "../components/EnvWarningBanner"
26-
import InlineLink from "../components/Link"
2725
import { mdxTableComponents } from "../components/Table"
2826
import PageMetadata from "../components/PageMetadata"
2927
import TableOfContents, {
@@ -36,6 +34,7 @@ import YouTube from "../components/YouTube"
3634
import PostMergeBanner from "../components/Banners/PostMergeBanner"
3735
import FeedbackCard from "../components/FeedbackCard"
3836
import GlossaryTooltip from "../components/Glossary/GlossaryTooltip"
37+
import MdLink from "../components/MdLink"
3938

4039
import { isLangRightToLeft, TranslationKey } from "../utils/translations"
4140
import { Lang } from "../utils/languages"
@@ -198,7 +197,7 @@ const KBD = (props) => {
198197
// Note: you must pass components to MDXProvider in order to render them in markdown files
199198
// https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#mdxprovider
200199
const components = {
201-
a: InlineLink,
200+
a: MdLink,
202201
h1: H1,
203202
h2: H2,
204203
h3: H3,

src/templates/upgrade.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Card from "../components/Card"
3131
import Contributors from "../components/Contributors"
3232
import InfoBanner from "../components/InfoBanner"
3333
import UpgradeStatus from "../components/UpgradeStatus"
34-
import InlineLink, { BaseLink } from "../components/Link"
34+
import { BaseLink } from "../components/Link"
3535
import { mdxTableComponents } from "../components/Table"
3636
import BeaconChainActions from "../components/BeaconChainActions"
3737
import ShardChainsList from "../components/ShardChainsList"
@@ -51,6 +51,7 @@ import MergeInfographic from "../components/MergeInfographic"
5151
import FeedbackCard from "../components/FeedbackCard"
5252
import QuizWidget from "../components/Quiz/QuizWidget"
5353
import GlossaryTooltip from "../components/Glossary/GlossaryTooltip"
54+
import MdLink from "../components/MdLink"
5455
import {
5556
MobileButton,
5657
MobileButtonDropdown,
@@ -208,7 +209,7 @@ const P = (props: TextProps) => (
208209
// https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#mdxprovider
209210

210211
const components = {
211-
a: InlineLink,
212+
a: MdLink,
212213
h1: MDXH1,
213214
h2: H2,
214215
h3: H3,

src/templates/use-cases.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import YouTube from "../components/YouTube"
5252
import FeedbackCard from "../components/FeedbackCard"
5353
import QuizWidget from "../components/Quiz/QuizWidget"
5454
import GlossaryTooltip from "../components/Glossary/GlossaryTooltip"
55+
import MdLink from "../components/MdLink"
5556

5657
import { isLangRightToLeft } from "../utils/translations"
5758
import { getSummaryPoints } from "../utils/getSummaryPoints"
@@ -109,7 +110,7 @@ export const Paragraph = (props: ChildOnlyProp) => (
109110
// Note: you must pass components to MDXProvider in order to render them in markdown files
110111
// https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#mdxprovider
111112
const components = {
112-
a: InlineLink,
113+
a: MdLink,
113114
h1: H1,
114115
h2: H2,
115116
h3: H3,

0 commit comments

Comments
 (0)