From 2586cfa9b043bbd282b7e4b1cebd34844eea7abb Mon Sep 17 00:00:00 2001 From: Aaron Carlino Date: Tue, 12 Nov 2019 17:05:31 +1300 Subject: [PATCH] fix icons --- gatsby-config.js | 2 +- src/components/ChildrenOf.tsx | 5 +++-- src/components/Header.tsx | 9 +++++++-- src/types/index.ts | 9 +++++---- src/utils/nodes.ts | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/gatsby-config.js b/gatsby-config.js index c4876a5..5d3edd6 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -51,7 +51,7 @@ module.exports = { resolve: `gatsby-plugin-purgecss`, options: { printRejected: false, - whitelist: ['.algolia-autocomplete'], + whitelist: ['algolia-autocomplete'], ignore: ['prismjs/','docsearch.js/', 'src/theme/assets/search/algolia.css'], //purgeOnly : ['components/', '/main.css', 'bootstrap/'], } diff --git a/src/components/ChildrenOf.tsx b/src/components/ChildrenOf.tsx index 873bec9..03b6df8 100644 --- a/src/components/ChildrenOf.tsx +++ b/src/components/ChildrenOf.tsx @@ -4,14 +4,15 @@ import { Link } from 'gatsby'; import { getChildren, getSiblings } from '../utils/nodes'; const createCards = (children: SilverstripeDocument[]): ReactElement[] => { - return children.map(({ summary, slug, title, icon }) => { + return children.map(({ summary, slug, title, icon, iconBrand }) => { + const iconClass = iconBrand ? `fab fa-${iconBrand}` : `fas fa-${icon || 'file-alt'}` return (
- + {title}
diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 7e07a84..df3d4b3 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -9,16 +9,21 @@ interface HeaderProps { } const handleNavigate = (e: any): void => { + if (typeof window === 'undefined') { + return; + } + const currentNode = getCurrentNode(); const ver = e.target.value; if (currentNode) { const newPath = currentNode.slug.replace(/^\/en\/[0-9]+\//, `/en/${ver}/`); const otherNode = getNodes().find(n => n.slug === newPath); + // This has to be a hard refresh, because the sidebar needs to unmount if (otherNode) { - navigate(otherNode.slug); + window.location.href = otherNode.slug; } else { - navigate(`/en/${ver}`); + window.location.href = `/en/${ver}`; } } } diff --git a/src/types/index.ts b/src/types/index.ts index 9228210..fddb05f 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -25,10 +25,11 @@ export interface SilverstripeDocument { slug: string; isIndex: boolean; filePath: string; - introduction: string; - icon: string; - hideChildren: boolean; - hideSelf: boolean; + introduction?: string; + icon?: string; + iconBrand?: string; + hideChildren?: boolean; + hideSelf?: boolean; parentSlug: string; summary: string; fileTitle: string; diff --git a/src/utils/nodes.ts b/src/utils/nodes.ts index 3a1ed0d..ebd6fd6 100644 --- a/src/utils/nodes.ts +++ b/src/utils/nodes.ts @@ -4,7 +4,6 @@ import { HierarchyQuery, SilverstripeDocument } from '../types'; import sortFiles from './sortFiles'; let __nodes: SilverstripeDocument[] | undefined; -let __path: string | null = null; let __currentNode: SilverstripeDocument | null = null; let __currentVersion: string | null = null; let __home: SilverstripeDocument | null = null; @@ -27,6 +26,7 @@ const getNodes = (): SilverstripeDocument[] => { isIndex introduction icon + iconBrand hideChildren slug parentSlug