Skip to content
Permalink
Newer
Older
100644 126 lines (118 sloc) 4.11 KB
1
import React from 'react';
2
import Document, { Head, Main, NextScript } from 'next/document';
3
import CleanCSS from 'clean-css';
4
import getContext from 'docs/src/modules/styles/getContext';
5
import config from 'docs/src/config';
6
7
const cleanCSS = new CleanCSS();
8
9
class MyDocument extends Document {
10
render() {
11
const { canonical, stylesContext } = this.props;
12
13
return (
14
<html lang="en" dir="ltr">
15
<Head>
16
<title>Material-UI</title>
17
<meta
18
name="description"
19
content="React Components that Implement Google's Material Design."
20
/>
21
<meta charSet="utf-8" />
22
{/* Use minimum-scale=1 to enable GPU rasterization */}
23
<meta
24
name="viewport"
25
content={
26
'user-scalable=0, initial-scale=1, ' +
27
'minimum-scale=1, width=device-width, height=device-height'
28
}
29
/>
30
{/*
31
manifest.json provides metadata used when your web app is added to the
32
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
33
*/}
34
<link rel="manifest" href="/static/manifest.json" />
35
{/* PWA primary color */}
36
<meta name="theme-color" content={stylesContext.theme.palette.primary[500]} />
37
<link
38
rel="stylesheet"
39
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"
40
/>
41
<style id="insertion-point-jss" />
42
{/* Twitter */}
43
<meta name="twitter:card" content="summary" />
44
<meta name="twitter:site" content="@MaterialUI" />
45
<meta name="twitter:title" content="Material-UI" />
46
<meta
47
name="twitter:description"
48
content="React Components that Implement Google's Material Design."
49
/>
50
<meta name="twitter:image" content="https://material-ui-next.com/static/brand.png" />
51
{/* Facebook */}
52
<meta property="og:type" content="website" />
53
<meta property="og:title" content="Material-UI" />
54
<meta
55
property="og:description"
56
content="React Components that Implement Google's Material Design."
57
/>
58
<meta property="og:image" content="https://material-ui-next.com/static/brand.png" />
59
<link rel="shortcut icon" href="/static/favicon.ico" />
60
<link rel="canonical" href={canonical} />
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
<Component sheetsRegistry={context.sheetsRegistry} {...props} />
106
107
let css = context.sheetsRegistry.toString();
108
if (process.env.NODE_ENV === 'production') {
109
css = cleanCSS.minify(css).styles;
110
}
111
112
return {
113
...page,
114
stylesContext: context,
115
canonical: `https://material-ui-next.com${ctx.req.url.replace(/\/$/, '')}/`,
116
styles: (
117
<style
118
id="jss-server-side"
119
// eslint-disable-next-line react/no-danger
120
dangerouslySetInnerHTML={{ __html: css }}
121
/>
122
),
123
};
124
};
125
126
export default MyDocument;