Skip to content
Permalink
Newer
Older
100644 127 lines (119 sloc) 4.17 KB
1
import React from 'react';
2
import Document, { Head, Main, NextScript } from 'next/document';
3
import CleanCSS from 'clean-css';
4
import getPageContext from 'docs/src/modules/styles/getPageContext';
5
import config from 'docs/src/config';
6
7
const cleanCSS = new CleanCSS();
8
9
class MyDocument extends Document {
10
render() {
11
const { canonical, pageContext } = this.props;
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={pageContext.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
<meta property="og:locale" content="en_US" />
60
<link rel="shortcut icon" href="/static/favicon.ico" />
61
<link rel="canonical" href={canonical} />
62
</Head>
63
<body>
64
<Main />
65
{/* Global Site Tag (gtag.js) - Google Analytics */}
66
<script async src={`https://www.googletagmanager.com/gtag/js?id=${config.google.id}`} />
67
<script
68
// eslint-disable-next-line react/no-danger
69
dangerouslySetInnerHTML={{
70
__html: `
71
window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments)};
72
gtag('js', new Date());
73
`,
74
}}
75
/>
76
<NextScript />
77
<script async src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js" />
78
</body>
79
</html>
80
);
81
}
82
}
83
84
MyDocument.getInitialProps = ctx => {
85
// Resolution order
86
//
87
// On the server:
88
// 1. page.getInitialProps
89
// 2. document.getInitialProps
90
// 3. page.render
91
// 4. document.render
92
//
93
// On the server with error:
94
// 2. document.getInitialProps
95
// 3. page.render
96
// 4. document.render
97
//
98
// On the client
99
// 1. page.getInitialProps
100
// 3. page.render
101
102
// Get the context of the page to collected side effects.
103
const pageContext = getPageContext();
104
const page = ctx.renderPage(Component => props => (
105
<Component pageContext={pageContext} {...props} />
108
let css = pageContext.sheetsRegistry.toString();
109
if (process.env.NODE_ENV === 'production') {
110
css = cleanCSS.minify(css).styles;
111
}
112
113
return {
114
...page,
115
pageContext,
116
canonical: `https://material-ui-next.com${ctx.req.url.replace(/\/$/, '')}/`,
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;