forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.tsx
52 lines (42 loc) · 1.32 KB
/
search.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
import type { GetServerSideProps } from 'next'
import searchVersions from '../lib/search/versions.js'
import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext'
import { DefaultLayout } from 'components/DefaultLayout'
import { Search } from 'components/search/index'
type Props = {
mainContext: MainContextT
}
export default function Page({ mainContext }: Props) {
return (
<MainContext.Provider value={mainContext}>
<DefaultLayout>
<Search />
</DefaultLayout>
</MainContext.Provider>
)
}
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
// The dedicated search results page is, as of Sep 2022 not enabled by
// default.
if (!process.env.ENABLE_SEARCH_RESULTS_PAGE) {
return { notFound: true }
}
const req = context.req as any
const res = context.res as any
const version = req.context.currentVersion
const searchVersion = searchVersions[Array.isArray(version) ? version[0] : version]
if (!searchVersion) {
// E.g. someone loaded `/en/[email protected]/search`
// That's going to 404 in the XHR later but it simply shouldn't be
// a valid starting page.
return {
notFound: true,
}
}
const mainContext = await getMainContext(req, res)
return {
props: {
mainContext,
},
}
}