fix: 트리 노드에 마지막 경로 세그먼트만 표시
/about/press → press, /about → about, / → / 들여쓰기로 계층이 표현되므로 전체 경로 반복 불필요 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -29,14 +29,20 @@ interface PageTreeNodeProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL에서 도메인을 제거하고 경로만 반환.
|
* URL에서 마지막 경로 세그먼트만 반환.
|
||||||
* 예: "https://example.com/about" -> "/about"
|
* 루트는 "/", 나머지는 마지막 세그먼트만 표시.
|
||||||
|
* 예: "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 {
|
try {
|
||||||
const parsed = new URL(url);
|
const parsed = new URL(url);
|
||||||
const path = parsed.pathname + parsed.search;
|
const path = parsed.pathname;
|
||||||
return path || "/";
|
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 {
|
} catch {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@ -55,7 +61,7 @@ export function PageTreeNode({
|
|||||||
const children = childrenPages.get(page.url) || [];
|
const children = childrenPages.get(page.url) || [];
|
||||||
const hasChildren = children.length > 0;
|
const hasChildren = children.length > 0;
|
||||||
const isSelected = selectedUrl === page.url;
|
const isSelected = selectedUrl === page.url;
|
||||||
const displayPath = getPathFromUrl(page.url);
|
const displayPath = getDisplayName(page.url);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user