File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed
Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -102,14 +102,35 @@ async function* traverseDirectory(
102102
103103export const buildEnd = async ( ) => {
104104 if ( ! useMirror ) return ;
105- for await ( const filePathName of traverseDirectory (
106- process . cwd ( ) + '/.vitepress/dist' ,
107- ) ) {
105+ const baseDir = posixPath ( process . cwd ( ) + '/.vitepress/dist' ) ;
106+ const relativePath = ( v : string ) => {
107+ return v . substring ( baseDir . length ) ;
108+ } ;
109+ const htmlUrlMap : Record < string , string > = { } ;
110+ for await ( const filePathName of traverseDirectory ( baseDir ) ) {
108111 if ( filePathName . endsWith ( '.html' ) ) {
109- const textFileName = filePathName + '.txt ' ;
112+ const textFileName = filePathName + '.md ' ;
110113 await fs . copyFile ( filePathName , textFileName ) ;
114+ htmlUrlMap [ relativePath ( filePathName ) ] = relativePath ( textFileName ) ;
111115 }
112116 }
117+ Object . keys ( htmlUrlMap ) . forEach ( ( k ) => {
118+ if ( k . endsWith ( '/index.html' ) ) {
119+ htmlUrlMap [ k . replace ( / i n d e x \. h t m l $ / , '' ) ] = htmlUrlMap [ k ] ;
120+ } else if ( k . endsWith ( '.html' ) ) {
121+ htmlUrlMap [ k . replace ( / \. h t m l $ / , '' ) ] = htmlUrlMap [ k ] ;
122+ }
123+ } ) ;
124+ await fs . writeFile (
125+ baseDir + '/_config.json' ,
126+ JSON . stringify (
127+ {
128+ htmlUrlMap,
129+ } ,
130+ undefined ,
131+ 2 ,
132+ ) ,
133+ ) ;
113134} ;
114135
115136const Parser =
You can’t perform that action at this time.
0 commit comments