|
| 1 | +import styled from "@emotion/styled"; |
| 2 | +import { useEffect, useState } from "react"; |
| 3 | + |
| 4 | +const menus = [ |
| 5 | + { |
| 6 | + text: "파이콘 한국", |
| 7 | + subMenu: [ |
| 8 | + { text: "파이콘 한국 소개", href: "/about" }, |
| 9 | + { text: "파이콘 한국 2025", href: "/2025" }, |
| 10 | + { text: "파이콘 한국 행동강령(CoC)", href: "/coc" }, |
| 11 | + { text: "파이썬 사용자 모임", href: "/user-group" }, |
| 12 | + { |
| 13 | + text: "역대 파이콘 행사", |
| 14 | + href: "/past-events", |
| 15 | + subMenu: [ |
| 16 | + { text: "2025", href: "/2025" }, |
| 17 | + { text: "2024", href: "/2024" }, |
| 18 | + { text: "2023", href: "/2023" }, |
| 19 | + { text: "2022", href: "/2022" }, |
| 20 | + { text: "2021", href: "/2021" }, |
| 21 | + { text: "2020", href: "/2020" }, |
| 22 | + ], |
| 23 | + }, |
| 24 | + { text: "파이콘 한국 건강 관련 안내", href: "/health" }, |
| 25 | + ], |
| 26 | + }, |
| 27 | + { |
| 28 | + text: "프로그램", |
| 29 | + subMenu: [ |
| 30 | + { text: "튜토리얼", href: "/tutorial" }, |
| 31 | + { text: "스프린트", href: "/sprint" }, |
| 32 | + { text: "포스터 세션", href: "/poster" }, |
| 33 | + ], |
| 34 | + }, |
| 35 | + { |
| 36 | + text: "세션", |
| 37 | + subMenu: [ |
| 38 | + { text: "세션 목록", href: "/sessions" }, |
| 39 | + { text: "세션 시간표", href: "/schedule" }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + { |
| 43 | + text: "구매", |
| 44 | + subMenu: [ |
| 45 | + { text: "티켓 구매", href: "/tickets" }, |
| 46 | + { text: "굿즈 구매", href: "/goods" }, |
| 47 | + { text: "결제 내역", href: "/payments" }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + { |
| 51 | + text: "후원하기", |
| 52 | + subMenu: [ |
| 53 | + { text: "후원사 안내", href: "/sponsors" }, |
| 54 | + { text: "개인 후원자", href: "/individual-sponsors" }, |
| 55 | + ], |
| 56 | + }, |
| 57 | +]; |
| 58 | + |
| 59 | +function findBreadcrumbInfo(path: string) { |
| 60 | + if (path === "/" || path === "") { |
| 61 | + return { |
| 62 | + paths: [{ text: "홈", href: "/" }], |
| 63 | + title: "홈", |
| 64 | + }; |
| 65 | + } |
| 66 | + |
| 67 | + const normalizedPath = path.replace(/^\/|\/$/g, ""); |
| 68 | + |
| 69 | + let breadcrumbPaths = [{ text: "홈", href: "/" }]; |
| 70 | + let pageTitle = ""; |
| 71 | + |
| 72 | + for (const menu of menus) { |
| 73 | + for (const subMenu of menu.subMenu) { |
| 74 | + const subMenuPath = subMenu.href.replace(/^\/|\/$/g, ""); |
| 75 | + |
| 76 | + if (subMenuPath === normalizedPath) { |
| 77 | + breadcrumbPaths.push({ text: menu.text, href: subMenu.href }); |
| 78 | + pageTitle = subMenu.text; |
| 79 | + return { paths: breadcrumbPaths, title: pageTitle }; |
| 80 | + } |
| 81 | + |
| 82 | + if (subMenu.subMenu) { |
| 83 | + for (const thirdMenu of subMenu.subMenu) { |
| 84 | + const thirdMenuPath = thirdMenu.href.replace(/^\/|\/$/g, ""); |
| 85 | + |
| 86 | + if (thirdMenuPath === normalizedPath) { |
| 87 | + breadcrumbPaths.push({ text: menu.text, href: subMenu.href }); |
| 88 | + breadcrumbPaths.push({ text: subMenu.text, href: subMenu.href }); |
| 89 | + pageTitle = thirdMenu.text; |
| 90 | + return { paths: breadcrumbPaths, title: pageTitle }; |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + return { |
| 98 | + paths: [{ text: "홈", href: "/" }], |
| 99 | + title: normalizedPath.charAt(0).toUpperCase() + normalizedPath.slice(1), |
| 100 | + }; |
| 101 | +} |
| 102 | + |
| 103 | +export default function BreadCrumb() { |
| 104 | + const [breadcrumbInfo, setBreadcrumbInfo] = useState({ |
| 105 | + paths: [{ text: "홈", href: "/" }], |
| 106 | + title: "파이콘 한국 행동강령(CoC)", |
| 107 | + }); |
| 108 | + |
| 109 | + useEffect(() => { |
| 110 | + const mockPathInfo = { |
| 111 | + paths: [ |
| 112 | + { text: "홈", href: "/" }, |
| 113 | + { text: "파이콘 한국", href: "/about" }, |
| 114 | + ], |
| 115 | + title: "파이콘 한국 행동강령(CoC)", |
| 116 | + }; |
| 117 | + setBreadcrumbInfo(mockPathInfo); |
| 118 | + }, []); |
| 119 | + |
| 120 | + return ( |
| 121 | + <BreadCrumbContainer> |
| 122 | + <BreadcrumbPathContainer> |
| 123 | + {breadcrumbInfo.paths.map((item, index) => ( |
| 124 | + <span key={index}> |
| 125 | + {index > 0 && <span className="separator">></span>} |
| 126 | + <a href={item.href}>{item.text}</a> |
| 127 | + </span> |
| 128 | + ))} |
| 129 | + </BreadcrumbPathContainer> |
| 130 | + <PageTitle>{breadcrumbInfo.title}</PageTitle> |
| 131 | + </BreadCrumbContainer> |
| 132 | + ); |
| 133 | +} |
| 134 | + |
| 135 | +const BreadCrumbContainer = styled.div` |
| 136 | + width: 100%; |
| 137 | + padding: 14px 117px; |
| 138 | + background-color: rgba(255, 255, 255, 0.7); |
| 139 | + background-image: linear-gradient( |
| 140 | + rgba(255, 255, 255, 0.7), |
| 141 | + rgba(255, 255, 255, 0.45) |
| 142 | + ); |
| 143 | + box-shadow: 0 1px 10px rgba(0, 0, 0, 0.1); |
| 144 | + display: flex; |
| 145 | + flex-direction: column; |
| 146 | + gap: 5px; |
| 147 | +`; |
| 148 | + |
| 149 | +const BreadcrumbPathContainer = styled.div` |
| 150 | + font-size: 9.75px; |
| 151 | + font-weight: 300; |
| 152 | + color: #000000; |
| 153 | + display: flex; |
| 154 | + align-items: center; |
| 155 | + gap: 0; |
| 156 | +
|
| 157 | + a { |
| 158 | + color: #000000; |
| 159 | + text-decoration: none; |
| 160 | +
|
| 161 | + &:hover { |
| 162 | + text-decoration: underline; |
| 163 | + } |
| 164 | + } |
| 165 | +
|
| 166 | + .separator { |
| 167 | + color: #4e869d; |
| 168 | + margin: 0 5px; |
| 169 | + } |
| 170 | +`; |
| 171 | + |
| 172 | +const PageTitle = styled.h1` |
| 173 | + font-size: 27px; |
| 174 | + font-weight: 600; |
| 175 | + color: #000000; |
| 176 | + margin: 0; |
| 177 | +`; |
0 commit comments