@@ -21,6 +21,32 @@ const isDir = async (path: string) => {
2121// 获取根目录
2222const rootPath = resolve ( import . meta. dirname , '../' ) ;
2323
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+
2450// TODO 对于 solution,需要递归读取
2551// const questions = ['lcci', 'lcof', 'lcof2', 'lcp', 'solution'];
2652// FIXME lcof 较为特殊,似乎中文名加上空格,导致服务崩溃
@@ -37,7 +63,7 @@ for (const question of questions) {
3763 continue ;
3864 }
3965 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 ) } ` ;
4167 }
4268}
4369
0 commit comments