@@ -28,6 +28,7 @@ import {
28
28
Table ,
29
29
} from '@/components'
30
30
import { useI18n } from '@/i18n'
31
+ import { NavItemGroup } from '@/navigation'
31
32
32
33
const mdxComponents = {
33
34
blockquote : Blockquote ,
@@ -75,13 +76,21 @@ export const MDXLayout = ({ pagePath, navItems, frontmatter, outline, children }
75
76
const { pathWithoutLocale } = useI18n ( )
76
77
77
78
// Compute some values for the `NavContext`
78
- const { pageNavItems , previousPage, currentPage, nextPage } = useMemo ( ( ) => {
79
+ const { previousPage, currentPage, nextPage, currentGroup } = useMemo ( ( ) => {
79
80
let previousPage = null
80
81
let currentPage = null
81
82
let nextPage = null
83
+ let currentGroup = null
82
84
const pageNavItems = navItems . flatMap ( ( navItem ) => {
83
85
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
+ } )
85
94
}
86
95
if ( 'path' in navItem ) {
87
96
return [ navItem ]
@@ -97,7 +106,7 @@ export const MDXLayout = ({ pagePath, navItems, frontmatter, outline, children }
97
106
}
98
107
pageNavItemIndex ++
99
108
}
100
- return { pageNavItems , previousPage, currentPage, nextPage }
109
+ return { previousPage, currentPage, nextPage, currentGroup : currentGroup as NavItemGroup | null }
101
110
} , [ navItems , pathWithoutLocale ] )
102
111
103
112
// 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 }
129
138
} , [ outline , outlineItemIsInOrAboveView ] )
130
139
131
140
return (
132
- < NavContext . Provider value = { { pagePath, navItems, pageNavItems , previousPage, currentPage, nextPage } } >
141
+ < NavContext . Provider value = { { pagePath, navItems, previousPage, currentPage, nextPage, currentGroup } } >
133
142
< DocumentContext . Provider value = { { frontmatter, outline, markOutlineItem, highlightedOutlineItemId } } >
134
143
< NextSeo title = { `${ frontmatter ?. title ? `${ frontmatter . title } - ` : '' } The Graph Docs` } />
135
144
@@ -155,7 +164,12 @@ export const MDXLayout = ({ pagePath, navItems, frontmatter, outline, children }
155
164
</ div >
156
165
157
166
< 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 }
159
173
< MDXProvider components = { mdxComponents } > { children } </ MDXProvider >
160
174
</ article >
161
175
0 commit comments