fix: 트리 노드에 마지막 경로 세그먼트만 표시

/about/press → press, /about → about, / → /
들여쓰기로 계층이 표현되므로 전체 경로 반복 불필요

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jungwoo choi
2026-02-14 07:26:30 +09:00
parent 645ec56bd1
commit 9c41b2f95d

View File

@ -29,14 +29,20 @@ interface PageTreeNodeProps {
}
/**
* URL에서 도메인을 제거하고 경로만 반환.
* 예: "https://example.com/about" -> "/about"
* URL에서 마지막 경로 세그먼트만 반환.
* 루트는 "/", 나머지는 마지막 세그먼트만 표시.
* 예: "https://example.com/" -> "/"
* "https://example.com/about" -> "about"
* "https://example.com/about/press" -> "press"
*/
function getPathFromUrl(url: string): string {
function getDisplayName(url: string): string {
try {
const parsed = new URL(url);
const path = parsed.pathname + parsed.search;
return path || "/";
const path = parsed.pathname;
if (path === "/" || path === "") return "/";
const clean = path.endsWith("/") ? path.slice(0, -1) : path;
const segments = clean.split("/").filter(Boolean);
return segments[segments.length - 1] || "/";
} catch {
return url;
}
@ -55,7 +61,7 @@ export function PageTreeNode({
const children = childrenPages.get(page.url) || [];
const hasChildren = children.length > 0;
const isSelected = selectedUrl === page.url;
const displayPath = getPathFromUrl(page.url);
const displayPath = getDisplayName(page.url);
return (
<div>