From 162bd4d75b74dba1f7114f71ad2507bde72101fd Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Mon, 25 Feb 2019 20:11:11 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=92=AB=20Add=20Algolia=20DocSearch=20?= =?UTF-8?q?(#3332)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Algolia DocSearch * Add human-readable selector for teaser --- website/meta/site.json | 4 ++ website/src/components/icon.js | 2 + website/src/components/navigation.js | 84 +++++++++++++++-------- website/src/components/search.js | 52 ++++++++++++++ website/src/components/title.js | 3 +- website/src/html.js | 43 ++++++++++++ website/src/images/icons/search.svg | 3 + website/src/styles/navigation.module.sass | 49 ++++++++----- website/src/styles/search.module.sass | 57 +++++++++++++++ website/src/templates/index.js | 12 +++- 10 files changed, 264 insertions(+), 45 deletions(-) create mode 100644 website/src/components/search.js create mode 100644 website/src/html.js create mode 100644 website/src/images/icons/search.svg create mode 100644 website/src/styles/search.module.sass diff --git a/website/meta/site.json b/website/meta/site.json index 847a14b55..2b65e1d84 100644 --- a/website/meta/site.json +++ b/website/meta/site.json @@ -22,6 +22,10 @@ "id": "83b0498b1e7fa3c91ce68c3f1", "list": "89ad33e698" }, + "docSearch": { + "apiKey": "371e26ed49d29a27bd36273dfdaf89af", + "indexName": "spacy" + }, "spacyVersion": "2.1", "binderUrl": "ines/spacy-io-binder", "binderBranch": "nightly", diff --git a/website/src/components/icon.js b/website/src/components/icon.js index 246820a2f..d9f0ce7c8 100644 --- a/website/src/components/icon.js +++ b/website/src/components/icon.js @@ -18,6 +18,7 @@ import { ReactComponent as YesIcon } from '../images/icons/yes.svg' import { ReactComponent as NoIcon } from '../images/icons/no.svg' import { ReactComponent as NeutralIcon } from '../images/icons/neutral.svg' import { ReactComponent as OfflineIcon } from '../images/icons/offline.svg' +import { ReactComponent as SearchIcon } from '../images/icons/search.svg' import classes from '../styles/icon.module.sass' @@ -39,6 +40,7 @@ const icons = { no: NoIcon, neutral: NeutralIcon, offline: OfflineIcon, + search: SearchIcon, } const Icon = ({ name, width, height, inline, variant, className }) => { diff --git a/website/src/components/navigation.js b/website/src/components/navigation.js index abf8a913b..bd83f7c44 100644 --- a/website/src/components/navigation.js +++ b/website/src/components/navigation.js @@ -1,6 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' import classNames from 'classnames' +import { navigate } from 'gatsby' import Link from './link' import Icon from './icon' @@ -8,36 +9,64 @@ import { github } from './util' import { ReactComponent as Logo } from '../images/logo.svg' import classes from '../styles/navigation.module.sass' -const Navigation = ({ title, items, section, children }) => ( - + ) +} Navigation.defaultProps = { items: [], @@ -52,6 +81,7 @@ Navigation.propTypes = { }) ), section: PropTypes.string, + search: PropTypes.node, } export default Navigation diff --git a/website/src/components/search.js b/website/src/components/search.js new file mode 100644 index 000000000..0ea4ec993 --- /dev/null +++ b/website/src/components/search.js @@ -0,0 +1,52 @@ +import React, { useEffect, useState } from 'react' +import PropTypes from 'prop-types' +import { window } from 'browser-monads' + +import Icon from './icon' +import classes from '../styles/search.module.sass' + +const Search = ({ id, placeholder, settings }) => { + const { apiKey, indexName } = settings + const [isInitialized, setIsInitialized] = useState(false) + useEffect(() => { + if (!isInitialized) { + setIsInitialized(true) + window.docsearch({ + apiKey, + indexName, + inputSelector: `#${id}`, + debug: false, + }) + } + }, window.docsearch) + return ( +
+ + +
+ ) +} + +Search.defaultProps = { + id: 'docsearch', + placeholder: 'Search docs', +} + +Search.propTypes = { + settings: PropTypes.shape({ + apiKey: PropTypes.string.isRequired, + indexName: PropTypes.string.isRequired, + }).isRequired, + id: PropTypes.string.isRequired, + placeholder: PropTypes.string.isRequired, +} + +export default Search diff --git a/website/src/components/title.js b/website/src/components/title.js index 285ad9192..1eadb3deb 100644 --- a/website/src/components/title.js +++ b/website/src/components/title.js @@ -1,5 +1,6 @@ import React from 'react' import PropTypes from 'prop-types' +import classNames from 'classnames' import Button from './button' import Tag from './tag' @@ -34,7 +35,7 @@ const Title = ({ title, tag, version, teaser, source, image, children, ...props )} - {teaser &&
{teaser}
} + {teaser &&
{teaser}
} {children} diff --git a/website/src/html.js b/website/src/html.js new file mode 100644 index 000000000..53e50bc8a --- /dev/null +++ b/website/src/html.js @@ -0,0 +1,43 @@ +import React from 'react' +import PropTypes from 'prop-types' + +export default function HTML(props) { + return ( + + + + + + {props.headComponents} + + + + {props.preBodyComponents} + +
+ {props.postBodyComponents} + +