Skip to content

Commit 86f8fbe

Browse files
committed
navbarにページタイトル
1 parent 92c9dba commit 86f8fbe

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

app/navbar.tsx

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1+
"use client";
2+
13
import Link from "next/link";
24
import { AccountMenu } from "./accountMenu";
35
import { ThemeToggle } from "./[docs_id]/themeToggle";
6+
import { usePathname } from "next/navigation";
7+
import { pagesList } from "./pagesList";
8+
9+
function PageTitle() {
10+
const pathname = usePathname();
11+
12+
if(pathname === "/"){
13+
return <>へようこそ</>;
14+
}
15+
16+
const currentDocsId = pathname.replace(/^\//, "");
17+
const currentGroup = pagesList.find((group) => currentDocsId.startsWith(group.id));
18+
const currentPage = currentGroup?.pages.find((page) => `${currentGroup.id}-${page.id}` === currentDocsId);
19+
if(currentPage){
20+
return <>
21+
<span className="text-base mr-2">{currentGroup?.lang}-{currentPage.id}.</span>
22+
<span>{currentPage.title}</span>
23+
</>
24+
}
25+
26+
console.warn(`navbar page name is not defined for pathname ${pathname}`);
27+
return null;
28+
}
429
export function Navbar() {
30+
531
return (
632
<>
733
{/* fixedのヘッダーの分だけスクロールするコンテンツを下に移動するためのdiv */}
@@ -31,16 +57,18 @@ export function Navbar() {
3157
</label>
3258
</div>
3359
{/* サイドバーが表示されていない場合のみ */}
34-
<div className="flex-1">
35-
<Link href="/" className="flex items-center">
36-
<img
37-
src="/icon.svg"
38-
alt="my.code(); Logo"
39-
className="inline-block w-8 h-8 mr-2"
40-
/>
41-
<span className="font-bold text-xl font-mono">my.code();</span>
42-
</Link>
60+
<Link href="/" className="flex items-center">
61+
<img
62+
src="/icon.svg"
63+
alt="my.code(); Logo"
64+
className="inline-block w-8 h-8 mr-2"
65+
/>
66+
<span className="font-bold text-xl font-mono">my.code();</span>
67+
</Link>
68+
<div className="flex-1 hidden md:inline text-nowrap overflow-hidden text-ellipsis font-bold text-xl">
69+
<PageTitle />
4370
</div>
71+
<div className="flex-1 md:hidden" />
4472
<ThemeToggle />
4573
<AccountMenu />
4674
</div>

0 commit comments

Comments
 (0)