forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
150 lines (138 loc) · 4.98 KB
/
index.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
148
149
150
import { GetServerSideProps } from 'next'
import {
MainContextT,
MainContext,
getMainContextFromRequest,
useMainContext,
} from 'components/context/MainContext'
import { DefaultLayout } from 'components/DefaultLayout'
import { useTranslation } from 'components/hooks/useTranslation'
import { useVersion } from 'components/hooks/useVersion'
import { LinkExternalIcon } from '@primer/octicons-react'
import { useRouter } from 'next/router'
import { OctocatHeader } from 'components/landing/OctocatHeader'
import { ArticleList } from 'components/landing/ArticleList'
import { Search } from 'components/Search'
type FeaturedLink = {
href: string
title: string
intro: string
}
type Props = {
mainContext: MainContextT
popularLinks: Array<FeaturedLink>
gettingStartedLinks: Array<FeaturedLink>
}
export default function MainLanding({ mainContext, gettingStartedLinks, popularLinks }: Props) {
return (
<MainContext.Provider value={mainContext}>
<DefaultLayout>
<LandingPage gettingStartedLinks={gettingStartedLinks} popularLinks={popularLinks} />
</DefaultLayout>
</MainContext.Provider>
)
}
type LandingPageProps = {
popularLinks: Array<FeaturedLink>
gettingStartedLinks: Array<FeaturedLink>
}
function LandingPage(props: LandingPageProps) {
const router = useRouter()
const { gettingStartedLinks, popularLinks } = props
const { activeProducts, isFPT } = useMainContext()
const { currentVersion } = useVersion()
const { t } = useTranslation(['homepage', 'search', 'toc'])
return (
<div>
{/* <!-- Hero --> */}
<section id="landing" className="color-bg-tertiary">
<Search isStandalone={true}>
{({ SearchInput, SearchResults }) => {
return (
<div className="container-xl px-3 px-md-6 pb-6 pb-lg-9">
<div className="gutter gutter-xl-spacious pt-6 pt-lg-0 d-lg-flex flex-row-reverse flex-items-center">
<div className="col-lg-7">
<OctocatHeader />
</div>
<div className="col-lg-5 mt-6">
<h1 className="h1-mktg mb-3">{t('search:need_help')}</h1>
{SearchInput}
</div>
</div>
<div className="mt-3">{SearchResults}</div>
</div>
)
}}
</Search>
</section>
{/* <!-- Explore by product --> */}
<section className="container-xl pb-lg-4 my-8 px-3 px-md-6">
<div className="">
<h2 className="text-mono f5 text-normal color-text-secondary text-md-center mb-4">
{t('explore_by_product')}
</h2>
<div className="d-flex flex-wrap gutter gutter-xl-spacious">
{activeProducts.map((product) => {
if (!isFPT && !product.versions?.includes(currentVersion) && !product.external) {
return null
}
const href = `${!product.external ? `/${router.locale}` : ''}${
product.versions?.includes(currentVersion) && !isFPT
? `/${currentVersion}/${product.id}`
: product.href
}`
return (
<div className="d-flex flex-column col-12 col-sm-6 col-lg-3 pb-4" key={product.id}>
<a
className="btn-mktg flex-auto d-flex flex-items-center btn-outline-mktg btn-large-mktg ws-normal "
href={href}
target={product.external ? '_blank' : undefined}
>
{product.name}
{product.external && (
<span className="ml-1">
<LinkExternalIcon />
</span>
)}
</a>
</div>
)
})}
</div>
</div>
</section>
<div className="px-3 px-md-6 container-xl">
<div className="featured-links container-xl">
<div className="gutter gutter-xl-spacious clearfix">
<div className="col-12 col-lg-6 mb-md-4 mb-lg-0 float-left">
<ArticleList
title={t('toc:getting_started')}
variant="spaced"
articles={gettingStartedLinks}
/>
</div>
<div className="col-12 col-lg-6 float-left">
<ArticleList title={t('toc:popular')} variant="spaced" articles={popularLinks} />
</div>
</div>
</div>
</div>
</div>
)
}
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
const req = context.req as any
return {
props: {
mainContext: getMainContextFromRequest(req),
gettingStartedLinks: req.context.featuredLinks.gettingStarted.map(
({ title, href, intro }: any) => ({ title, href, intro })
),
popularLinks: req.context.featuredLinks.popular.map(({ title, href, intro }: any) => ({
title,
href,
intro,
})),
},
}
}