forked from stellar/new-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml.js
59 lines (55 loc) · 1.61 KB
/
html.js
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
import React from "react";
import PropTypes from "prop-types";
import { PORTAL_TARGETS } from "constants/domNodes";
import { IS_PRODUCTION } from "constants/env";
export default function HTML(props) {
return (
<html {...props.htmlAttributes}>
<head>
<meta charSet="utf-8" />
<meta httpEquiv="x-ua-compatible" content="ie=edge" />
{IS_PRODUCTION && (
<script async src="https://www.google-analytics.com/analytics.js" />
)}
{props.headComponents}
</head>
<body {...props.bodyAttributes}>
{props.preBodyComponents}
<div
key={`body`}
id="___gatsby"
dangerouslySetInnerHTML={{ __html: props.body }}
/>
<script
dangerouslySetInnerHTML={{
__html: `
if (document.location.pathname.startsWith('/api')) {
var el = document.getElementById(document.location.pathname)
if (el) {
el.scrollIntoView();
}
}
`,
}}
/>
{props.postBodyComponents}
<script
src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"
integrity="sha384-8uEk67aWSZHvjtAX9hf2AB+KzYcssy31vRRTi9oP81zHtyIj7PQGAykGbQpB1L2J"
crossorigin="anonymous"
></script>
{Object.values(PORTAL_TARGETS).map((name) => (
<div key={name} id={name} />
))}
</body>
</html>
);
}
HTML.propTypes = {
htmlAttributes: PropTypes.object,
headComponents: PropTypes.array,
bodyAttributes: PropTypes.object,
preBodyComponents: PropTypes.array,
body: PropTypes.string,
postBodyComponents: PropTypes.array,
};