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_INDEX=silverstripe
GATSBY_DOCSEARCH_INDEX=silverstripe
DOCS_CONTEXT=docs

3
.gitignore vendored
View File

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

View File

@ -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`,

View File

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

View File

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