@@ -11,22 +11,28 @@ interface SidebarItem {
1111}
1212
1313/**
14- * pages/posts 폴더 구조를 기반으로 자동으로 사이드바를 생성하는 함수
14+ * 폴더 구조를 기반으로 자동으로 사이드바를 생성하는 함수
15+ * @param folderPath - pages 폴더 내의 상대 경로 (예: 'posts', 'projects')
16+ * @param urlPath - URL 경로 (예: '/posts', '/projects')
1517 */
16- export function generateSidebar ( ) : DefaultTheme . SidebarItem [ ] {
17- const postsDir = join ( process . cwd ( ) , "pages" , "posts" ) ;
18+ export function generateSidebar (
19+ folderPath : string = "posts" ,
20+ urlPath ?: string ,
21+ ) : DefaultTheme . SidebarItem [ ] {
22+ const targetDir = join ( process . cwd ( ) , "pages" , folderPath ) ;
23+ const finalUrlPath = urlPath || `/${ folderPath } ` ;
1824
1925 try {
20- // posts 폴더가 존재하지 않으면 빈 사이드바 반환
21- if ( ! statSync ( postsDir ) . isDirectory ( ) ) {
26+ // 폴더가 존재하지 않으면 빈 사이드바 반환
27+ if ( ! statSync ( targetDir ) . isDirectory ( ) ) {
2228 return [ ] ;
2329 }
2430 } catch ( error ) {
25- // posts 폴더가 없으면 빈 사이드바 반환
31+ // 폴더가 없으면 빈 사이드바 반환
2632 return [ ] ;
2733 }
2834
29- const sidebarItems = generateSidebarItems ( postsDir , "/posts" ) ;
35+ const sidebarItems = generateSidebarItems ( targetDir , finalUrlPath ) ;
3036 return sidebarItems ;
3137}
3238
@@ -85,7 +91,7 @@ function generateSidebarItems(dir: string, basePath: string): SidebarItem[] {
8591 if ( indexFile ) {
8692 items . unshift ( {
8793 text : "개요" ,
88- link : basePath === "/posts" ? "/posts/" : basePath ,
94+ link : ` ${ basePath } /` ,
8995 } ) ;
9096 }
9197 } catch ( error ) {
@@ -123,10 +129,16 @@ function formatTitle(name: string): string {
123129
124130/**
125131 * 특정 경로에 대한 사이드바만 생성 (다중 사이드바 사용 시)
132+ * @param folderPath - pages 폴더 내의 상대 경로
133+ * @param urlPath - URL 경로
126134 */
127- export function generateSidebarForPath ( path : string ) : DefaultTheme . SidebarItem [ ] {
135+ export function generateSidebarForPath (
136+ folderPath : string ,
137+ urlPath ?: string ,
138+ ) : DefaultTheme . SidebarItem [ ] {
128139 const pagesDir = join ( process . cwd ( ) , "pages" ) ;
129- const targetDir = join ( pagesDir , path ) ;
140+ const targetDir = join ( pagesDir , folderPath ) ;
141+ const finalUrlPath = urlPath || `/${ folderPath } ` ;
130142
131143 try {
132144 if ( ! statSync ( targetDir ) . isDirectory ( ) ) {
@@ -136,5 +148,5 @@ export function generateSidebarForPath(path: string): DefaultTheme.SidebarItem[]
136148 return [ ] ;
137149 }
138150
139- return generateSidebarItems ( targetDir , `/posts/ ${ path } ` ) ;
151+ return generateSidebarItems ( targetDir , finalUrlPath ) ;
140152}
0 commit comments