-
Notifications
You must be signed in to change notification settings - Fork 671
/
index.js
executable file
·71 lines (64 loc) · 1.93 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
// @ts-check
/** @jsx jsx */
import { jsx } from 'theme-ui'
import Layout from './components/layout'
export { default as Banner } from './components/banner'
export { default as Tiles } from './components/tiles'
export { default as Cards } from './components/cards'
export { default as Note } from './components/note'
/**
* @param {import("gatsby").WrapPageElementBrowserArgs} props
*/
export const WrapPageElement = ({ element, props }) => (
<Layout {...props} children={element} />
)
/**
* @see https://docsearch.algolia.com/
* @param {import("gatsby").RenderBodyArgs} args
*/
export const setDocSearchComponents = ({
setHeadComponents,
setPostBodyComponents,
}) => {
setHeadComponents([
<link
key="algolia-css"
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css"
/>,
])
setPostBodyComponents([
<script
key="algolia-cdn"
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>,
<script
key="algolia-script"
type="text/javascript"
dangerouslySetInnerHTML={{
__html: `
var lastSearchInput = null;
var observer = new MutationObserver(function () {
var searchSelector = "#algolia-docs-search";
var searchInput = document.querySelector(searchSelector);
if (lastSearchInput !== searchInput) {
docsearch({
apiKey: "84ed820927eee5fa5018c9f1abe70390",
indexName: "theme-ui",
inputSelector: searchSelector,
debug: true
})
lastSearchInput = searchInput;
}
});
document.addEventListener("DOMContentLoaded", function() {
observer.observe(document, {
childList: true,
subtree: true
});
});
`,
}}
/>,
])
}