Skip to content

Commit 1d5d668

Browse files
committed
navbarのタイトル表示ロジックを修正
1 parent f2e1867 commit 1d5d668

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

app/navbar.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ import { LanguageEntry } from "@/lib/docs";
88

99
function 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
}
3030
export function Navbar({ pagesList }: { pagesList: LanguageEntry[] }) {

0 commit comments

Comments
 (0)