From fd6dcf27be4e03f35947da4ecac542b9592bdc72 Mon Sep 17 00:00:00 2001 From: Aaron Carlino Date: Tue, 17 Dec 2019 14:04:09 +1300 Subject: [PATCH] Store context in site metadata --- .env.development | 3 ++- .gitignore | 3 +++ gatsby-config.js | 3 ++- src/components/SEO.tsx | 3 ++- src/components/SearchBox.tsx | 4 +++- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.env.development b/.env.development index f556442..16ea983 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,3 @@ GATSBY_DOCSEARCH_API_KEY=0ca39e6ea6a622b335fc0c71482aff54 -GATSBY_DOCSEARCH_INDEX=silverstripe \ No newline at end of file +GATSBY_DOCSEARCH_INDEX=silverstripe +DOCS_CONTEXT=docs \ No newline at end of file diff --git a/.gitignore b/.gitignore index 65629e9..84997e2 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,6 @@ yarn-error.log .pnp.js # Yarn Integrity file .yarn-integrity + +static/_redirects +public/_redirects \ No newline at end of file diff --git a/gatsby-config.js b/gatsby-config.js index 1e74193..741eb47 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -3,9 +3,10 @@ const path = require('path'); module.exports = { siteMetadata: { title: `Silverstripe CMS Documentation`, - description: `Developer documentation for the Silverstripe CMS and framework.`, + description: `Developer and user documentation for the Silverstripe CMS and framework.`, author: `The Silverstripe Community`, siteUrl: `https://doc.silverstripe.org`, + context: process.env.DOCS_CONTEXT, }, plugins: [ `gatsby-plugin-react-helmet`, diff --git a/src/components/SEO.tsx b/src/components/SEO.tsx index 568d159..72a9340 100644 --- a/src/components/SEO.tsx +++ b/src/components/SEO.tsx @@ -28,6 +28,7 @@ const SEO: StatelessComponent = ({ description, lang, meta, title }) = title description author + context } } } @@ -79,7 +80,7 @@ const SEO: StatelessComponent = ({ description, lang, meta, title }) = }, { name: `docsearch:context`, - content: process.env.DOCS_CONTEXT, + content: site.siteMetadata.context, }, ].concat(meta)} /> diff --git a/src/components/SearchBox.tsx b/src/components/SearchBox.tsx index af48263..fc64481 100644 --- a/src/components/SearchBox.tsx +++ b/src/components/SearchBox.tsx @@ -19,7 +19,9 @@ const autocompleteSelected = (e) => { const SearchBox: StatelessComponent = ({ identifier }): ReactElement|null => { useEffect(() => { if (typeof window === 'undefined') return; - + if (!process.env.GATSBY_DOCSEARCH_API_KEY) { + return; + } window.addEventListener( `autocomplete:selected`, autocompleteSelected,