@@ -118,7 +118,26 @@ function mapTocToSidebar(root, collapsable, prefix = '') {
118
118
if ( filename === '.DS_Store' ) { // 过滤.DS_Store文件
119
119
return
120
120
}
121
- let [ order , title , type ] = filename . split ( '.' ) ;
121
+ // let [order, title, type] = filename.split('.');
122
+
123
+ const fileNameArr = filename . split ( '.' )
124
+ const isDir = stat . isDirectory ( )
125
+ let order = '' , title = '' , type = '' ;
126
+ if ( fileNameArr . length === 2 ) {
127
+ order = fileNameArr [ 0 ] ;
128
+ title = fileNameArr [ 1 ] ;
129
+ } else {
130
+ const firstDotIndex = filename . indexOf ( '.' ) ;
131
+ const lastDotIndex = filename . lastIndexOf ( '.' ) ;
132
+ order = filename . substring ( 0 , firstDotIndex ) ;
133
+ type = filename . substring ( lastDotIndex + 1 ) ;
134
+ if ( isDir ) {
135
+ title = filename . substring ( firstDotIndex + 1 ) ;
136
+ } else {
137
+ title = filename . substring ( firstDotIndex + 1 , lastDotIndex ) ;
138
+ }
139
+ }
140
+
122
141
order = parseInt ( order , 10 ) ;
123
142
if ( isNaN ( order ) || order < 0 ) {
124
143
log ( chalk . yellow ( `warning: 该文件 "${ file } " 序号出错,请填写正确的序号` ) )
@@ -127,7 +146,7 @@ function mapTocToSidebar(root, collapsable, prefix = '') {
127
146
if ( sidebar [ order ] ) { // 判断序号是否已经存在
128
147
log ( chalk . yellow ( `warning: 该文件 "${ file } " 的序号在同一级别中重复出现,将会被覆盖` ) )
129
148
}
130
- if ( stat . isDirectory ( ) ) { // 是文件夹目录
149
+ if ( isDir ) { // 是文件夹目录
131
150
sidebar [ order ] = {
132
151
title,
133
152
collapsable, // 是否可折叠,默认true
0 commit comments