Skip to content

Commit 9bf7fe4

Browse files
committed
fix: 사이드바 단일 카테고리로 변경
1 parent 660623f commit 9bf7fe4

File tree

2 files changed

+24
-45
lines changed

2 files changed

+24
-45
lines changed

.vitepress/plugins/sidebar.ts

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,58 +40,17 @@ function generateSidebarItems(dir: string, basePath: string): SidebarItem[] {
4040
const items: SidebarItem[] = [];
4141

4242
try {
43-
const entries = readdirSync(dir, { withFileTypes: true });
43+
items.push({ text: "전체 게시글", link: `${basePath}/` });
4444

45-
// 파일과 폴더를 분리하여 정렬
46-
const files = entries.filter(
47-
(entry: Dirent) => entry.isFile() && entry.name.endsWith(".md"),
48-
);
45+
const entries = readdirSync(dir, { withFileTypes: true });
4946
const folders = entries.filter((entry: Dirent) => entry.isDirectory());
5047

51-
// 폴더 처리 (카테고리로 취급)
5248
for (const folder of folders.sort((a: Dirent, b: Dirent) => a.name.localeCompare(b.name))) {
53-
const folderPath = join(dir, folder.name);
5449
const folderBasePath = `${basePath}/${folder.name}`;
5550

56-
const folderItems = generateSidebarItems(folderPath, folderBasePath);
57-
58-
if (folderItems.length > 0) {
59-
items.push({
60-
text: formatTitle(folder.name),
61-
items: folderItems,
62-
collapsed: true, // 기본적으로 접혀있도록 설정
63-
});
64-
}
65-
}
66-
67-
// 파일 처리
68-
for (const file of files.sort((a: Dirent, b: Dirent) => a.name.localeCompare(b.name))) {
69-
const fileName = basename(file.name, extname(file.name));
70-
71-
// index.md 파일은 해당 폴더의 대표 페이지로 처리
72-
if (fileName === "index") {
73-
continue;
74-
}
75-
76-
const filePath = join(dir, file.name);
77-
const frontmatterTitle = getFrontmatterTitle(filePath);
78-
7951
items.push({
80-
// frontmatter title 우선, 없으면 파일명 사용
81-
text: frontmatterTitle || formatTitle(fileName),
82-
link: `${basePath}/${fileName}`,
83-
});
84-
}
85-
86-
// index.md 파일이 있으면 첫 번째 항목으로 추가
87-
const indexFile = files.find(
88-
(file: Dirent) => basename(file.name, extname(file.name)) === "index",
89-
);
90-
91-
if (indexFile) {
92-
items.unshift({
93-
text: "개요",
94-
link: `${basePath}/`,
52+
text: formatTitle(folder.name),
53+
link: `${folderBasePath}/`,
9554
});
9655
}
9756
} catch (error) {

.vitepress/theme/style.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,23 @@
134134
figcaption {
135135
font-size: 0.75rem;
136136
}
137+
138+
/**
139+
* Component: Sidebar
140+
* -------------------------------------------------------------------------- */
141+
142+
:root {
143+
--vp-sidebar-width: 180px;
144+
}
145+
146+
@media (min-width: 960px) {
147+
:root {
148+
--vp-sidebar-width: 220px;
149+
}
150+
}
151+
152+
@media (min-width: 1440px) {
153+
:root {
154+
--vp-sidebar-width: 240px;
155+
}
156+
}

0 commit comments

Comments
 (0)