|
| 1 | +"use client"; |
| 2 | + |
1 | 3 | import Link from "next/link"; |
2 | 4 | import { AccountMenu } from "./accountMenu"; |
3 | 5 | 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 | +} |
4 | 29 | export function Navbar() { |
| 30 | + |
5 | 31 | return ( |
6 | 32 | <> |
7 | 33 | {/* fixedのヘッダーの分だけスクロールするコンテンツを下に移動するためのdiv */} |
@@ -31,16 +57,18 @@ export function Navbar() { |
31 | 57 | </label> |
32 | 58 | </div> |
33 | 59 | {/* サイドバーが表示されていない場合のみ */} |
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 /> |
43 | 70 | </div> |
| 71 | + <div className="flex-1 md:hidden" /> |
44 | 72 | <ThemeToggle /> |
45 | 73 | <AccountMenu /> |
46 | 74 | </div> |
|
0 commit comments