-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path_document.tsx
More file actions
108 lines (97 loc) · 2.77 KB
/
_document.tsx
File metadata and controls
108 lines (97 loc) · 2.77 KB
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
import { cache } from '@emotion/css'
import createEmotionServer from '@emotion/server/create-instance'
import Document, {
DocumentContext,
DocumentInitialProps,
Head,
Html,
Main,
NextScript,
} from 'next/document'
import { ReactElement } from 'react'
import styled from 'styled-components'
import { BULMA_A, BULMA_GREY } from '../constants/colors'
export const renderStatic = async (html) => {
if (html === undefined) {
throw new Error('did you forget to return html from renderToString?')
}
const { extractCritical } = createEmotionServer(cache)
const { ids, css } = extractCritical(html)
return { html, ids, css }
}
const StyledHtml = styled.html`
a {
color: ${BULMA_A};
}
.has-text-grey {
color: ${BULMA_GREY} !important;
}
`
class BaseDocument extends Document {
static async getInitialProps(
ctx: DocumentContext,
): Promise<DocumentInitialProps> {
const initialProps = await Document.getInitialProps(ctx)
const page = await ctx.renderPage()
const { css, ids } = await renderStatic(page.html)
return {
...initialProps,
styles: (
<>
{initialProps.styles}
<style
data-emotion={`css ${ids.join(' ')}`}
dangerouslySetInnerHTML={{ __html: css }}
/>
</>
),
}
}
render(): ReactElement<any> {
return (
<StyledHtml as={Html} lang="en">
<Head>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.0/css/bulma.min.css"
integrity="sha256-aPeK/N8IHpHsvPBCf49iVKMdusfobKo2oxF8lRruWJg="
crossOrigin="anonymous"
/>
<link
href="https://fonts.googleapis.com/css?family=Roboto&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800&display=swap"
rel="stylesheet"
/>
<link
href="/static/css/react-draft-wysiwyg.css"
rel="stylesheet"
key="editor-css"
/>
<link
href="/static/css/react-datepicker.css"
rel="stylesheet"
key="datepicker-css"
/>
<link
href="/static/css/style-react-vis.css"
rel="stylesheet"
key="editor-css"
/>
<script src="https://status.pennlabs.org/banner.js" defer />
</Head>
<body>
<Main />
<NextScript />
</body>
</StyledHtml>
)
}
}
export default BaseDocument