/
ArticlePage.tsx
147 lines (136 loc) · 5.05 KB
/
ArticlePage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { useRouter } from 'next/router'
import cx from 'classnames'
import { Heading } from '@primer/components'
import { ZapIcon, InfoIcon, ShieldLockIcon } from '@primer/octicons-react'
import { Callout } from 'components/ui/Callout'
import { Link } from 'components/Link'
import { DefaultLayout } from 'components/DefaultLayout'
import { ArticleTitle } from 'components/article/ArticleTitle'
import { MiniTocItem, useArticleContext } from 'components/context/ArticleContext'
import { useTranslation } from 'components/hooks/useTranslation'
import { LearningTrackNav } from './LearningTrackNav'
import { MarkdownContent } from 'components/ui/MarkdownContent'
import { Lead } from 'components/ui/Lead'
import { ArticleGridLayout } from './ArticleGridLayout'
import { PlatformPicker } from 'components/article/PlatformPicker'
// Mapping of a "normal" article to it's interactive counterpart
const interactiveAlternatives: Record<string, { href: string }> = {
'/actions/automating-builds-and-tests/building-and-testing-nodejs': {
href: '/actions/automating-builds-and-tests/building-and-testing-nodejs-or-python?langId=nodejs',
},
'/actions/automating-builds-and-tests/building-and-testing-python': {
href: '/actions/automating-builds-and-tests/building-and-testing-nodejs-or-python?langId=python',
},
}
export const ArticlePage = () => {
const router = useRouter()
const {
title,
intro,
effectiveDate,
renderedPage,
contributor,
permissions,
includesPlatformSpecificContent,
product,
miniTocItems,
currentLearningTrack,
} = useArticleContext()
const { t } = useTranslation('pages')
const currentPath = router.asPath.split('?')[0]
const renderTocItem = (item: MiniTocItem) => {
return (
<li key={item.contents} className={cx(item.platform, 'mb-2 lh-condensed')}>
<div className="mb-2 lh-condensed" dangerouslySetInnerHTML={{ __html: item.contents }} />
{item.items && item.items.length > 0 ? (
<ul className="list-style-none pl-0 f5 mb-0 ml-3">{item.items.map(renderTocItem)}</ul>
) : null}
</li>
)
}
return (
<DefaultLayout>
<div className="container-xl px-3 px-md-6 my-4">
<ArticleGridLayout
topper={<ArticleTitle>{title}</ArticleTitle>}
intro={
<>
{contributor && (
<Callout variant="info" className="mb-3">
<p>
<span className="mr-2">
<InfoIcon />
</span>
{t('contributor_callout')} <a href={contributor.URL}>{contributor.name}</a>.
</p>
</Callout>
)}
{intro && (
<Lead data-testid="lead" data-search="lead">
{intro}
</Lead>
)}
{permissions && (
<div className="permissions-statement d-table">
<div className="d-table-cell pr-2">
<ShieldLockIcon size={16} />
</div>
<div className="d-table-cell" dangerouslySetInnerHTML={{ __html: permissions }} />
</div>
)}
{includesPlatformSpecificContent && <PlatformPicker variant="underlinenav" />}
{product && (
<Callout
variant="success"
className="mb-4"
dangerouslySetInnerHTML={{ __html: product }}
/>
)}
</>
}
toc={
<>
{!!interactiveAlternatives[currentPath] && (
<div className="flash mb-3">
<ZapIcon className="mr-2" />
<Link href={interactiveAlternatives[currentPath].href}>
Try the new interactive article
</Link>
</div>
)}
{miniTocItems.length > 1 && (
<>
<Heading as="h2" fontSize={1} id="in-this-article" className="mb-1">
<a className="Link--primary" href="#in-this-article">
{t('miniToc')}
</a>
</Heading>
<ul className="list-style-none pl-0 f5 mb-0">
{miniTocItems.map(renderTocItem)}
</ul>
</>
)}
</>
}
>
<div id="article-contents">
<MarkdownContent>{renderedPage}</MarkdownContent>
{effectiveDate && (
<div className="mt-4" id="effectiveDate">
Effective as of:{' '}
<time dateTime={new Date(effectiveDate).toISOString()}>
{new Date(effectiveDate).toDateString()}
</time>
</div>
)}
</div>
</ArticleGridLayout>
{currentLearningTrack?.trackName ? (
<div className="mt-4">
<LearningTrackNav track={currentLearningTrack} />
</div>
) : null}
</div>
</DefaultLayout>
)
}