Skip to content
Permalink
Newer
Older
100644 127 lines (119 sloc) 4.05 KB
1
// @flow
2
3
import React from 'react';
4
import Document, { Head, Main, NextScript } from 'next/document';
5
import CleanCSS from 'clean-css';
6
import JssProvider from 'react-jss/lib/JssProvider';
7
import getContext from 'docs/src/modules/styles/getContext';
8
import config from 'docs/src/config';
9
10
const cleanCSS = new CleanCSS();
11
12
class MyDocument extends Document {
13
render() {
14
return (
15
<html lang="en" dir="ltr">
16
<Head>
17
<title>Material-UI</title>
18
<meta
19
name="description"
20
content="React Components that Implement Google's Material Design."
21
/>
22
<meta charSet="utf-8" />
23
{/* Use minimum-scale=1 to enable GPU rasterization */}
24
<meta
25
name="viewport"
26
content={
27
'user-scalable=0, initial-scale=1, ' +
28
'minimum-scale=1, width=device-width, height=device-height'
29
}
30
/>
31
{/*
32
manifest.json provides metadata used when your web app is added to the
33
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
34
*/}
35
<link rel="manifest" href="/static/manifest.json" />
36
{/* PWA primary color */}
37
<meta name="theme-color" content={this.props.stylesContext.theme.palette.primary[500]} />
38
<link
39
rel="stylesheet"
40
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"
41
/>
42
<style id="insertion-point-jss" />
43
{/* Twitter */}
44
<meta name="twitter:card" content="summary" />
45
<meta name="twitter:site" content="@MaterialUI" />
46
<meta name="twitter:title" content="Material-UI" />
47
<meta
48
name="twitter:description"
49
content="React Components that Implement Google's Material Design."
50
/>
51
<meta name="twitter:image" content="https://material-ui-next.com/static/brand.png" />
52
{/* Facebook */}
53
<meta property="og:type" content="website" />
54
<meta property="og:title" content="Material-UI" />
55
<meta
56
property="og:description"
57
content="React Components that Implement Google's Material Design."
58
/>
59
<meta property="og:image" content="https://material-ui-next.com/static/brand.png" />
60
<link rel="shortcut icon" href="/static/favicon.ico" />
61
</Head>
62
<body>
63
<Main />
64
{/* Global Site Tag (gtag.js) - Google Analytics */}
65
<script async src={`https://www.googletagmanager.com/gtag/js?id=${config.google.id}`} />
66
<script
67
// eslint-disable-next-line react/no-danger
68
dangerouslySetInnerHTML={{
69
__html: `
70
window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments)};
71
gtag('js', new Date());
72
`,
73
}}
74
/>
75
<NextScript />
76
<script async src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js" />
77
</body>
78
</html>
79
);
80
}
81
}
82
83
MyDocument.getInitialProps = ctx => {
84
// Resolution order
85
//
86
// On the server:
87
// 1. page.getInitialProps
88
// 2. document.getInitialProps
89
// 3. page.render
90
// 4. document.render
91
//
92
// On the server with error:
93
// 2. document.getInitialProps
94
// 3. page.render
95
// 4. document.render
96
//
97
// On the client
98
// 1. page.getInitialProps
99
// 3. page.render
100
101
// Get the context to collected side effects.
102
const context = getContext();
103
const page = ctx.renderPage(Component => props => (
104
<JssProvider registry={context.sheetsRegistry} jss={context.jss}>
105
<Component {...props} />
106
</JssProvider>
107
));
108
109
let css = context.sheetsRegistry.toString();
110
if (process.env.NODE_ENV === 'production') {
111
css = cleanCSS.minify(css).styles;
112
}
113
114
return {
115
...page,
116
stylesContext: context,
117
styles: (
118
<style
119
id="jss-server-side"
120
// eslint-disable-next-line react/no-danger
121
dangerouslySetInnerHTML={{ __html: css }}
122
/>
123
),
124
};
125
};
126
127
export default MyDocument;