1- import fs from " node:fs" ;
2- import path from " node:path" ;
1+ import fs from ' node:fs' ;
2+ import path from ' node:path' ;
33
44export type SidebarItem = {
55 text : string ;
@@ -8,14 +8,14 @@ export type SidebarItem = {
88} ;
99export type Sidebar = Record < string , SidebarItem [ ] > ;
1010
11- const DOC_EXT = [ " .md" ] ;
11+ const DOC_EXT = [ ' .md' ] ;
1212const EXCLUDED_DIRS = new Set ( [
13- " .git" ,
14- " .github" ,
15- " .vitepress" ,
16- " node_modules" ,
17- " public" ,
18- "en" , // 排除 en 目录,避免在中文版导航中显示
13+ ' .git' ,
14+ ' .github' ,
15+ ' .vitepress' ,
16+ ' node_modules' ,
17+ ' public' ,
18+ 'en' , // 排除 en 目录,避免在中文版导航中显示
1919] ) ;
2020
2121function isDirectory ( p : string ) {
@@ -32,16 +32,16 @@ function isMarkdown(p: string) {
3232
3333function titleFromName ( name : string ) {
3434 // strip extension & use as-is (Chinese names kept)
35- return name . replace ( / \. m d $ / i, "" ) ;
35+ return name . replace ( / \. m d $ / i, '' ) ;
3636}
3737
3838function sortByPinyinOrName ( a : string , b : string ) {
39- return a . localeCompare ( b , " zh-Hans-CN-u-co-pinyin" ) ;
39+ return a . localeCompare ( b , ' zh-Hans-CN-u-co-pinyin' ) ;
4040}
4141
4242export function generateNavAndSidebar (
4343 rootDir : string ,
44- localePrefix : string = ""
44+ localePrefix : string = ''
4545) {
4646 const scanDir = localePrefix ? path . join ( rootDir , localePrefix ) : rootDir ;
4747
@@ -52,7 +52,7 @@ export function generateNavAndSidebar(
5252 const entries = fs . readdirSync ( scanDir ) ;
5353 const sections = entries
5454 . filter ( ( e : string ) => isDirectory ( path . join ( scanDir , e ) ) )
55- . filter ( ( e : string ) => ! EXCLUDED_DIRS . has ( e ) && ! e . startsWith ( "." ) ) ;
55+ . filter ( ( e : string ) => ! EXCLUDED_DIRS . has ( e ) && ! e . startsWith ( '.' ) ) ;
5656 sections . sort ( sortByPinyinOrName ) ;
5757
5858 const nav : { text : string ; link : string } [ ] = [ ] ;
@@ -68,13 +68,13 @@ export function generateNavAndSidebar(
6868 // Build sidebar for this section
6969 const items : SidebarItem [ ] = files . map ( ( f : string ) => ( {
7070 text : titleFromName ( f ) ,
71- link : `/${ localePrefix } ${ localePrefix ? "/" : "" } ${ encodeURI (
71+ link : `/${ localePrefix } ${ localePrefix ? '/' : '' } ${ encodeURI (
7272 dir
7373 ) } /${ encodeURI ( f ) } `,
7474 } ) ) ;
7575
7676 if ( items . length > 0 ) {
77- const sidebarKey = `/${ localePrefix } ${ localePrefix ? "/" : "" } ${ dir } /` ;
77+ const sidebarKey = `/${ localePrefix } ${ localePrefix ? '/' : '' } ${ dir } /` ;
7878 sidebar [ sidebarKey ] = [
7979 {
8080 text : dir ,
@@ -88,7 +88,7 @@ export function generateNavAndSidebar(
8888 // Empty section: still show in nav to directory index if exists
8989 nav . push ( {
9090 text : dir ,
91- link : `/${ localePrefix } ${ localePrefix ? "/" : "" } ${ encodeURI ( dir ) } /` ,
91+ link : `/${ localePrefix } ${ localePrefix ? '/' : '' } ${ encodeURI ( dir ) } /` ,
9292 } ) ;
9393 }
9494 }
0 commit comments