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