diff --git a/src/components/Footer/index.tsx b/src/components/Footer/index.tsx
index fff09081d5..a7bc73be6c 100644
--- a/src/components/Footer/index.tsx
+++ b/src/components/Footer/index.tsx
@@ -108,21 +108,6 @@ const Footer = ({sourcePath}: { sourcePath: string }) => {
-
-
)
}
diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx
index c621e7cb1a..fba9ca0023 100644
--- a/src/components/Header/index.tsx
+++ b/src/components/Header/index.tsx
@@ -3,10 +3,7 @@ import { Link } from "gatsby"
import HeaderLinks from "../HeaderLinks"
import Search from "../Search"
-interface Props {
- noSearch?: boolean
-}
-const Header = ({ noSearch }: Props) => {
+const Header = () => {
return (
@@ -20,8 +17,8 @@ const Header = ({ noSearch }: Props) => {
/>
GraphQL
-
- {noSearch || }
+
+
)
diff --git a/src/components/Link/index.tsx b/src/components/Link/index.tsx
index 4ea2e1b7d5..58aef00f64 100644
--- a/src/components/Link/index.tsx
+++ b/src/components/Link/index.tsx
@@ -2,7 +2,7 @@ import React from "react"
import { Link } from "gatsby"
interface Props {
- children: React.ReactNode
+ children?: React.ReactNode
href: string,
className?:string
}
diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx
index 12d134c65e..5aeef48ddd 100644
--- a/src/components/Search/index.tsx
+++ b/src/components/Search/index.tsx
@@ -1,10 +1,61 @@
-import React from "react"
+import React, {useEffect} from "react"
+
+// Added to the global runtime by the script tag further down the file.
+declare const docsearch: any | undefined
+
+
+
+// Runs the new docsearch function over possible search inputs
+const runDocsearchIfPossible = () => {
+ if (typeof docsearch !== 'undefined') {
+ const searches = ["algolia-search-input", "hero-search-input"]
+ for (const searchID of searches) {
+ if (!document.getElementById(searchID)) continue
+
+ docsearch({
+ apiKey: 'd103541f3e6041148aade2e746ed4d61',
+ indexName: 'graphql',
+ inputSelector: `#${searchID}`
+ });
+ }
+ }
+}
+
+const Search = ({searchID}: { searchID?: string}): JSX.Element => {
+ const searchInputID = searchID || "algolia-search-input"
+
+ // This extra bit of mis-direction ensures that non-essential code runs after
+ // the page is loaded
+ useEffect(() => {
+ runDocsearchIfPossible()
+
+ if (document.getElementById("algolia-search")) return
+
+ const searchScript = document.createElement('script');
+ searchScript.id = "algolia-search"
+ const searchCSS = document.createElement('link');
+
+ searchScript.src = "https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js";
+ searchScript.async = true;
+ searchScript.onload = () => {
+ if (typeof docsearch !== 'undefined') {
+ runDocsearchIfPossible()
+
+ searchCSS.rel = 'stylesheet';
+ searchCSS.href = 'https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css'
+ searchCSS.type = 'text/css';
+ document.body.appendChild(searchCSS);
+ }
+ }
+
+ document.body.appendChild(searchScript);
+ }, []);
+
-const Search = (): JSX.Element => {
return (
{
return (
@@ -39,4 +39,4 @@ export default ({ pageContext }) => {
)
- }
\ No newline at end of file
+ }