Permalink
material-ui/pages/_document.js
Newer
100644
138 lines (129 sloc)
4.65 KB
1
import React from 'react';
2
import Document, { Head, Main, NextScript } from 'next/document';
3
import postcss from 'postcss';
4
import autoprefixer from 'autoprefixer';
6
import getPageContext from 'docs/src/modules/styles/getPageContext';
11
// You can find a benchmark of the available CSS minifiers under
12
// https://github.com/GoalSmashers/css-minification-benchmark
13
// We have found that clean-css is faster than cssnano but the output is larger.
14
// Waiting for https://github.com/cssinjs/jss/issues/279
15
// 4% slower but 12% smaller output than doing it in a single step.
18
const prefixer = postcss([autoprefixer]);
27
<meta
28
name="description"
29
content="React Components that Implement Google's Material Design."
30
/>
31
{/* Use minimum-scale=1 to enable GPU rasterization */}
32
<meta
33
name="viewport"
34
content={
35
'user-scalable=0, initial-scale=1, ' +
36
'minimum-scale=1, width=device-width, height=device-height'
37
}
38
/>
39
{/*
40
manifest.json provides metadata used when your web app is added to the
41
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
42
*/}
43
<link rel="manifest" href="/static/manifest.json" />
44
{/* PWA primary color */}
45
<meta name="theme-color" content={pageContext.theme.palette.primary.main} />
46
<link
47
rel="stylesheet"
48
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"
49
/>
50
<style id="insertion-point-jss" />
51
{/* Twitter */}
53
<meta name="twitter:site" content="@MaterialUI" />
54
<meta name="twitter:title" content="Material-UI" />
55
<meta
56
name="twitter:description"
57
content="React Components that Implement Google's Material Design."
59
<meta name="twitter:image" content="https://material-ui.com/static/brand.png" />
60
{/* Facebook */}
61
<meta property="og:type" content="website" />
62
<meta property="og:title" content="Material-UI" />
63
<meta
64
property="og:description"
65
content="React Components that Implement Google's Material Design."
66
/>
67
<meta property="og:image" content="https://material-ui.com/static/brand.png" />
69
<link rel="shortcut icon" href="/static/favicon.ico" />
70
<link rel="canonical" href={canonical} />
74
{/* Global Site Tag (gtag.js) - Google Analytics */}
75
<script async src={`https://www.googletagmanager.com/gtag/js?id=${config.google.id}`} />
76
<script
77
// eslint-disable-next-line react/no-danger
78
dangerouslySetInnerHTML={{
79
__html: `
80
window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments)};
81
gtag('js', new Date());
82
`,
83
}}
84
/>
86
<script async src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js" />
93
MyDocument.getInitialProps = async ctx => {
94
// Resolution order
95
//
96
// On the server:
97
// 1. page.getInitialProps
98
// 2. document.getInitialProps
99
// 3. page.render
100
// 4. document.render
101
//
102
// On the server with error:
103
// 2. document.getInitialProps
104
// 3. page.render
105
// 4. document.render
106
//
107
// On the client
108
// 1. page.getInitialProps
109
// 3. page.render
110
111
// Get the context of the page to collected side effects.
112
const pageContext = getPageContext();
113
const page = ctx.renderPage(Component => props => (
118
if (process.env.NODE_ENV === 'production') {
119
const result1 = await prefixer.process(css, { from: undefined });
127
canonical: `https://material-ui.com${ctx.req.url.replace(/\/$/, '')}/`,
128
styles: (
129
<style
130
id="jss-server-side"
131
// eslint-disable-next-line react/no-danger
132
dangerouslySetInnerHTML={{ __html: css }}
133
/>
134
),
135
};
136
};
137
138
export default MyDocument;