-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
60 lines (50 loc) · 1.37 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
import Meta from '@/components/layout/meta';
import { getYearData } from '@/lib/years';
import { IndexProps } from '@/models/props';
import { GetServerSideProps, NextPage } from 'next';
import PageLayout from '../components/layout/page-layout';
import { parseSubdomainToYear } from '../utils/page.utils';
import dynamic from 'next/dynamic';
const NotFound = dynamic(() => import('@/components/layout/not-found'));
const Route: NextPage<IndexProps> = (props) => {
if (!props.found) {
return <NotFound {...props} />;
}
return (
<>
<Meta
color={props.colors.primary}
title={props.title}
description={props.description}
year={props.year}
logoUrl={props.logo.url}
font={props.font?.url}
/>
<PageLayout {...props} navLinks={props.navLinks} />
</>
);
};
type Params = {
route?: string[];
};
/**
* Runs serverside before the page is rendered
*/
export const getServerSideProps: GetServerSideProps<
IndexProps,
Params
> = async ({ req, locale, query, res }) => {
// Set cache headers
res.setHeader(
'Cache-Control',
'public, s-maxage=10, stale-while-revalidate=59'
);
const l = locale ?? 'sv';
const { password = '' } = query;
const year = parseSubdomainToYear(req);
const data = await getYearData(year, password.toString(), l);
return {
props: data,
};
};
export default Route;