@@ -14,6 +14,13 @@ const dataJsonMinPath = path.resolve(process.cwd(), 'dist', 'data.min.json');
1414const cssPath = path . resolve ( deployDir , 'css' , 'index.css' ) ;
1515const contributorsPath = path . resolve ( process . cwd ( ) , 'CONTRIBUTORS.svg' ) ;
1616
17+ function sanitizeCommandName ( value ) {
18+ return String ( value || '' )
19+ . replace ( / ^ \uFEFF / , '' )
20+ . replace ( / [ \u200B - \u200D \u2060 ] / g, '' )
21+ . trim ( ) ;
22+ }
23+
1724; ( async ( ) => {
1825 try {
1926 await FS . ensureDir ( deployDir ) ;
@@ -151,6 +158,7 @@ const contributorsPath = path.resolve(process.cwd(), 'CONTRIBUTORS.svg');
151158 let title = str . match ( / [ ^ = = = ] + (? = [ = = = ] ) / g) ;
152159 title = title [ 0 ] ? title [ 0 ] . replace ( / \n / g, '' ) : title [ 0 ] ;
153160 title = title . replace ( / \r / , '' )
161+ title = sanitizeCommandName ( title )
154162 // 命令名称
155163 json [ "n" ] = title ;
156164 // 命令路径
@@ -186,13 +194,15 @@ const contributorsPath = path.resolve(process.cwd(), 'CONTRIBUTORS.svg');
186194 const current_path = toPath . replace ( new RegExp ( `${ deployDir } ` ) , '' ) ;
187195 const tmpStr = await FS . readFile ( fromPath ) ;
188196 let mdPathName = '' ;
197+ let mdFileName = '' ;
189198 let mdhtml = '' ;
190199 let relative_path = '' ;
191200 if ( mdPath ) {
192201 // CSS/JS 引用相对地址
193202 relative_path = '../' ;
194- mdPathName = `/command/${ desJson . n } .md` ;
195- const READMESTR = await FS . readFile ( path . resolve ( mdPath , `${ desJson . n } .md` ) ) ;
203+ mdFileName = ( desJson . p ? String ( desJson . p ) . replace ( / ^ \/ / , '' ) : sanitizeCommandName ( desJson . n ) ) ;
204+ mdPathName = `/command/${ mdFileName } .md` ;
205+ const READMESTR = await FS . readFile ( path . resolve ( mdPath , `${ mdFileName } .md` ) ) ;
196206 mdhtml = await markdownToHTML ( READMESTR . toString ( ) ) ;
197207 }
198208 // 生成 HTML
0 commit comments