@@ -21,6 +21,32 @@ const isDir = async (path: string) => {
21
21
// 获取根目录
22
22
const rootPath = resolve ( import . meta. dirname , '../' ) ;
23
23
24
+ const getQuestionNo = ( title : string , dir : string ) : string => {
25
+ let dot = dir !== 'lcci' ? title . indexOf ( '.' ) : title . lastIndexOf ( '.' ) ;
26
+ let num = title
27
+ . slice ( 0 , dot )
28
+ . replace ( '面试题' , '' )
29
+ . replace ( '剑指 Offer II' , '' )
30
+ . replace ( 'LCP' , '' )
31
+ . replace ( 'LCS' , '' )
32
+ . trim ( )
33
+ . replace ( / ^ 0 + / , '' ) ; // Remove leading zeros
34
+
35
+ if ( num . endsWith ( '- III' ) ) {
36
+ num = num . slice ( 0 , - 5 ) + '.3' ;
37
+ } else if ( num . endsWith ( '- II' ) ) {
38
+ num = num . slice ( 0 , - 4 ) + '.2' ;
39
+ } else if ( num . endsWith ( '- I' ) ) {
40
+ num = num . slice ( 0 , - 3 ) + '.1' ;
41
+ }
42
+
43
+ num = num
44
+ . split ( '.' )
45
+ . map ( x => x . trim ( ) . replace ( / ^ 0 + / , '' ) )
46
+ . join ( '.' ) ;
47
+ return num ;
48
+ } ;
49
+
24
50
// TODO 对于 solution,需要递归读取
25
51
// const questions = ['lcci', 'lcof', 'lcof2', 'lcp', 'solution'];
26
52
// FIXME lcof 较为特殊,似乎中文名加上空格,导致服务崩溃
@@ -37,7 +63,7 @@ for (const question of questions) {
37
63
continue ;
38
64
}
39
65
items [ question ] . push ( { text : file , link : `${ question } /${ file } /README.md` } ) ;
40
- rewrites [ `${ question } /${ file } /README.md` ] = `${ question } /${ file } ` ;
66
+ rewrites [ `${ question } /${ file } /README.md` ] = `${ question } /${ getQuestionNo ( file , question ) } ` ;
41
67
}
42
68
}
43
69
0 commit comments