@@ -28,6 +28,7 @@ import {
2828 Table ,
2929} from '@/components'
3030import { useI18n } from '@/i18n'
31+ import { NavItemGroup } from '@/navigation'
3132
3233const mdxComponents = {
3334 blockquote : Blockquote ,
@@ -75,13 +76,21 @@ export const MDXLayout = ({ pagePath, navItems, frontmatter, outline, children }
7576 const { pathWithoutLocale } = useI18n ( )
7677
7778 // Compute some values for the `NavContext`
78- const { pageNavItems , previousPage, currentPage, nextPage } = useMemo ( ( ) => {
79+ const { previousPage, currentPage, nextPage, currentGroup } = useMemo ( ( ) => {
7980 let previousPage = null
8081 let currentPage = null
8182 let nextPage = null
83+ let currentGroup = null
8284 const pageNavItems = navItems . flatMap ( ( navItem ) => {
8385 if ( 'children' in navItem ) {
84- return navItem . children . filter ( ( childNavItem ) => 'path' in childNavItem )
86+ return navItem . children . filter ( ( childNavItem ) => {
87+ if ( 'path' in childNavItem ) {
88+ if ( childNavItem . path === pathWithoutLocale ) {
89+ currentGroup = navItem
90+ }
91+ return true
92+ }
93+ } )
8594 }
8695 if ( 'path' in navItem ) {
8796 return [ navItem ]
@@ -97,7 +106,7 @@ export const MDXLayout = ({ pagePath, navItems, frontmatter, outline, children }
97106 }
98107 pageNavItemIndex ++
99108 }
100- return { pageNavItems , previousPage, currentPage, nextPage }
109+ return { previousPage, currentPage, nextPage, currentGroup : currentGroup as NavItemGroup | null }
101110 } , [ navItems , pathWithoutLocale ] )
102111
103112 // Provide `markOutlineItem` to the `DocumentContext` so child `Heading` components can mark outline items as "in or above view" or not
@@ -129,7 +138,7 @@ export const MDXLayout = ({ pagePath, navItems, frontmatter, outline, children }
129138 } , [ outline , outlineItemIsInOrAboveView ] )
130139
131140 return (
132- < NavContext . Provider value = { { pagePath, navItems, pageNavItems , previousPage, currentPage, nextPage } } >
141+ < NavContext . Provider value = { { pagePath, navItems, previousPage, currentPage, nextPage, currentGroup } } >
133142 < DocumentContext . Provider value = { { frontmatter, outline, markOutlineItem, highlightedOutlineItemId } } >
134143 < NextSeo title = { `${ frontmatter ?. title ? `${ frontmatter . title } - ` : '' } The Graph Docs` } />
135144
@@ -155,7 +164,12 @@ export const MDXLayout = ({ pagePath, navItems, frontmatter, outline, children }
155164 </ div >
156165
157166 < article className = "graph-docs-content" sx = { mdxStyles } >
158- { frontmatter ?. title && < Heading . H1 > { frontmatter . title } </ Heading . H1 > }
167+ { currentGroup ? (
168+ < div className = "graph-docs-current-group" sx = { { display : 'none' } } >
169+ { currentGroup . title }
170+ </ div >
171+ ) : null }
172+ { frontmatter ?. title ? < Heading . H1 > { frontmatter . title } </ Heading . H1 > : null }
159173 < MDXProvider components = { mdxComponents } > { children } </ MDXProvider >
160174 </ article >
161175
0 commit comments