gatsby-theme-carbon 4.0.8 → 4.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-theme-carbon",
3
- "version": "4.0.8",
3
+ "version": "4.0.10",
4
4
  "main": "index.js",
5
5
  "author": "vpicone <vp@vincepic.one> (@vpicone)",
6
6
  "repository": {
@@ -23,6 +23,7 @@ const LeftNav = (props) => {
23
23
  leftNavScrollTop,
24
24
  setLeftNavScrollTop,
25
25
  toggleNavState,
26
+ pathPrefix,
26
27
  } = useContext(NavContext);
27
28
 
28
29
  const [isTreeView, setIsTreeView] = useState();
@@ -97,7 +98,11 @@ const LeftNav = (props) => {
97
98
  onClick={closeSwitcher}
98
99
  onKeyPress={closeSwitcher}>
99
100
  {isTreeView ? (
100
- <LeftNavTree items={navItems} theme={props.theme} />
101
+ <LeftNavTree
102
+ items={navItems}
103
+ theme={props.theme}
104
+ pathPrefix={pathPrefix}
105
+ />
101
106
  ) : (
102
107
  <SideNav
103
108
  ref={sideNavRef}
@@ -11,7 +11,7 @@ import { dfs } from '../../util/NavTree';
11
11
 
12
12
  import LeftNavResourceLinks from './ResourceLinks';
13
13
 
14
- const LeftNavTree = ({ items, theme }) => {
14
+ const LeftNavTree = ({ items, theme, pathPrefix }) => {
15
15
  const [itemNodes, setItemNodes] = useState([]);
16
16
  const [treeActiveItem, setTreeActiveItem] = useState({});
17
17
  const [activePath, setActivePath] = useState('');
@@ -66,8 +66,11 @@ const LeftNavTree = ({ items, theme }) => {
66
66
  useEffect(() => {
67
67
  const stripTrailingSlash = (str) =>
68
68
  str.endsWith('/') ? str.slice(0, -1) : str;
69
- setActivePath(stripTrailingSlash(location.pathname));
70
- }, [location.pathname]);
69
+ const base = pathPrefix
70
+ ? location.pathname.replace(pathPrefix, '')
71
+ : location.pathname;
72
+ setActivePath(stripTrailingSlash(base));
73
+ }, [location.pathname, pathPrefix]);
71
74
 
72
75
  const getItemPath = (item) =>
73
76
  item.path || slugify(item.title, { lower: true, strict: true });
@@ -97,7 +100,7 @@ const LeftNavTree = ({ items, theme }) => {
97
100
  activeNode = dfs(itemNodes, isTabActive);
98
101
  }
99
102
  setTreeActiveItem(activeNode);
100
- }, [isTreeNodeActive, itemNodes]);
103
+ }, [isTreeNodeActive, itemNodes, isTabActive]);
101
104
 
102
105
  const isTreeNodeExpanded = (node) =>
103
106
  !!dfs([node], (evalNode) =>
@@ -1,4 +1,5 @@
1
1
  import React, { useMemo, useReducer, useState } from 'react';
2
+ import usePathprefix from '../hooks/usePathprefix';
2
3
 
3
4
  const NavContext = React.createContext({
4
5
  leftNavIsOpen: false,
@@ -19,6 +20,7 @@ const reducer = (state, action) => {
19
20
  }
20
21
  };
21
22
  export const NavContextProvider = ({ children }) => {
23
+ const pathPrefix = usePathprefix();
22
24
  const [
23
25
  { leftNavIsOpen, searchIsOpen, switcherIsOpen, leftNavScrollOffset },
24
26
  dispatch,
@@ -47,6 +49,7 @@ export const NavContextProvider = ({ children }) => {
47
49
  leftNavScrollOffset,
48
50
  leftNavScrollTop,
49
51
  setLeftNavScrollTop,
52
+ pathPrefix,
50
53
  }),
51
54
  [
52
55
  leftNavIsOpen,
@@ -58,6 +61,7 @@ export const NavContextProvider = ({ children }) => {
58
61
  leftNavScrollOffset,
59
62
  leftNavScrollTop,
60
63
  setLeftNavScrollTop,
64
+ pathPrefix,
61
65
  ]
62
66
  );
63
67