@@ -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 ) {
0 commit comments