This repository was archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_document.js
More file actions
76 lines (70 loc) · 2.37 KB
/
_document.js
File metadata and controls
76 lines (70 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import Document, { Html, Head, Main, NextScript } from "next/document";
import { Helmet } from "react-helmet";
// Adopted from the react-helmet example in next.js repository:
// https://github.com/zeit/next.js/blob/canary/examples/with-react-helmet/pages/_document.js
class TheDocument extends Document {
static async getInitialProps(...args) {
const documentProps = await super.getInitialProps(...args);
// see https://github.com/nfl/react-helmet#server-usage for more information
// 'head' was occupied by 'renderPage().head', we cannot use it
return { ...documentProps, helmet: Helmet.renderStatic() };
}
// should render on <html>
get helmetHtmlAttrComponents() {
return this.props.helmet.htmlAttributes.toComponent();
}
// should render on <body>
get helmetBodyAttrComponents() {
return this.props.helmet.bodyAttributes.toComponent();
}
// should render on <head>
get helmetHeadComponents() {
return Object.keys(this.props.helmet)
.filter((el) => el !== "htmlAttributes" && el !== "bodyAttributes")
.map((el) => this.props.helmet[el].toComponent());
}
render() {
return (
<Html {...this.helmetHtmlAttrComponents}>
<Head>
{this.helmetHeadComponents}
<link
rel="apple-touch-icon"
sizes="180x180"
href="/static/icons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/static/icons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/static/icons/favicon-16x16.png"
/>
<link rel="manifest" href="/static/icons/site.webmanifest" />
<link
rel="mask-icon"
href="/static/icons/safari-pinned-tab.svg"
color="#36678d"
/>
<link rel="shortcut icon" href="/static/icons/favicon.ico" />
<meta name="msapplication-TileColor" content="#36678d" />
<meta
name="msapplication-config"
content="/static/icons/browserconfig.xml"
/>
<meta name="theme-color" content="#ffffff" />
</Head>
<body {...this.helmetBodyAttrComponents}>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default TheDocument;