File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,23 +8,23 @@ import { LanguageEntry } from "@/lib/docs";
88
99function PageTitle ( { pagesList } : { pagesList : LanguageEntry [ ] } ) {
1010 const pathname = usePathname ( ) ;
11+ const pathnameMatch = pathname . match ( / ^ \/ ( [ \w - _ ] + ) \/ ( [ \w - _ ] + ) .* ?/ ) ;
12+ const currentLang = pathnameMatch ?. [ 1 ] ;
13+ const currentPageId = pathnameMatch ?. [ 2 ] ;
1114
1215 if ( pathname === "/" ) {
1316 return < > へようこそ</ > ;
1417 }
1518
16- const currentDocsId = pathname . replace ( / ^ \/ / , "" ) ;
17- const currentGroup = pagesList . find ( ( group ) => currentDocsId . startsWith ( `${ group . id } /` ) ) ;
18- const pageIndex = currentGroup ?. pages . findIndex ( ( page ) => `${ currentGroup . id } /${ page . slug } ` === currentDocsId ) ?? - 1 ;
19- const currentPage = pageIndex >= 0 ? currentGroup ?. pages [ pageIndex ] : undefined ;
20- if ( currentPage ) {
19+ const currentGroup = pagesList . find ( ( group ) => group . id === currentLang ) ;
20+ const currentPage = currentGroup ?. pages . find ( ( page ) => page . slug === currentPageId ) ;
21+ if ( currentGroup && currentPage ) {
2122 return < >
22- < span className = "text-base mr-2" > { currentGroup ? .name } -{ pageIndex + 1 } .</ span >
23+ < span className = "text-base mr-2" > { currentGroup . name } -{ currentPage . index } .</ span >
2324 < span > { currentPage . name } </ span >
2425 </ >
2526 }
2627
27- console . warn ( `navbar page name is not defined for pathname ${ pathname } ` ) ;
2828 return null ;
2929}
3030export function Navbar ( { pagesList } : { pagesList : LanguageEntry [ ] } ) {
You can’t perform that action at this time.
0 commit comments