1+ import fs from 'fs' ;
2+ import path from 'path' ;
3+
4+ const docsRoot = path . resolve ( __dirname , '..' ) ;
5+
6+ /**
7+ * 파일 이름을 Title Case 형태의 텍스트로 변환합니다.
8+ * e.g., 'error-subscription.md' -> 'Error Subscription'
9+ * @param {string } filename - 변환할 파일 이름
10+ */
11+ function toTitleCase ( filename ) {
12+ return filename . replace ( / - / g, ' ' ) . replace ( / \. m d $ / , '' )
13+ . split ( ' ' )
14+ . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) )
15+ . join ( ' ' ) ;
16+ }
17+
18+ /**
19+ * 지정된 디렉토리 경로에서 사이드바 그룹 객체를 생성합니다.
20+ * @param {string } dirPath - 'docs' 기준의 상대 경로 (e.g., 'api/rest')
21+ * @param {string } groupText - 사이드바에 표시될 그룹 이름
22+ */
23+ function getSidebarGroup ( dirPath , groupText ) {
24+ const fullPath = path . join ( docsRoot , dirPath ) ;
25+ try {
26+ const files = fs . readdirSync ( fullPath ) ;
27+
28+ const items = files
29+ . filter ( file => file . endsWith ( '.md' ) )
30+ . map ( file => {
31+ const link = `/${ dirPath } /${ file . replace ( / \. m d $ / , '' ) } ` ;
32+ return { text : toTitleCase ( file ) , link} ;
33+ } ) ;
34+
35+ return { text : groupText , items} ;
36+ } catch ( error ) {
37+ console . warn ( `Could not read directory for sidebar group: ${ fullPath } ` ,
38+ error ) ;
39+ return { text : groupText , items : [ ] } ;
40+ }
41+ }
42+
43+ export const sidebar = [
44+ getSidebarGroup ( 'api' , 'REST APIs' ) ,
45+ ] ;
0 commit comments