Store context in site metadata

This commit is contained in:
Aaron Carlino 2019-12-17 14:04:09 +13:00
parent d59778b795
commit fd6dcf27be
5 changed files with 12 additions and 4 deletions

View File

@ -1,2 +1,3 @@
GATSBY_DOCSEARCH_API_KEY=0ca39e6ea6a622b335fc0c71482aff54 GATSBY_DOCSEARCH_API_KEY=0ca39e6ea6a622b335fc0c71482aff54
GATSBY_DOCSEARCH_INDEX=silverstripe GATSBY_DOCSEARCH_INDEX=silverstripe
DOCS_CONTEXT=docs

3
.gitignore vendored
View File

@ -68,3 +68,6 @@ yarn-error.log
.pnp.js .pnp.js
# Yarn Integrity file # Yarn Integrity file
.yarn-integrity .yarn-integrity
static/_redirects
public/_redirects

View File

@ -3,9 +3,10 @@ const path = require('path');
module.exports = { module.exports = {
siteMetadata: { siteMetadata: {
title: `Silverstripe CMS Documentation`, 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`, author: `The Silverstripe Community`,
siteUrl: `https://doc.silverstripe.org`, siteUrl: `https://doc.silverstripe.org`,
context: process.env.DOCS_CONTEXT,
}, },
plugins: [ plugins: [
`gatsby-plugin-react-helmet`, `gatsby-plugin-react-helmet`,

View File

@ -28,6 +28,7 @@ const SEO: StatelessComponent<SEOProps> = ({ description, lang, meta, title }) =
title title
description description
author author
context
} }
} }
} }
@ -79,7 +80,7 @@ const SEO: StatelessComponent<SEOProps> = ({ description, lang, meta, title }) =
}, },
{ {
name: `docsearch:context`, name: `docsearch:context`,
content: process.env.DOCS_CONTEXT, content: site.siteMetadata.context,
}, },
].concat(meta)} ].concat(meta)}
/> />

View File

@ -19,7 +19,9 @@ const autocompleteSelected = (e) => {
const SearchBox: StatelessComponent<SearchBoxProps> = ({ identifier }): ReactElement|null => { const SearchBox: StatelessComponent<SearchBoxProps> = ({ identifier }): ReactElement|null => {
useEffect(() => { useEffect(() => {
if (typeof window === 'undefined') return; if (typeof window === 'undefined') return;
if (!process.env.GATSBY_DOCSEARCH_API_KEY) {
return;
}
window.addEventListener( window.addEventListener(
`autocomplete:selected`, `autocomplete:selected`,
autocompleteSelected, autocompleteSelected,