@@ -19,7 +19,7 @@ async function execute() {
19
19
const fs = require ( 'fs-extra' ) ;
20
20
const readMetadata = require ( './readMetadata.js' ) ;
21
21
const path = require ( 'path' ) ;
22
- const { minifyCss, isSeparateCss, autoPrefixCss} = require ( './utils' ) ;
22
+ const { minifyCss, isSeparateCss, autoPrefixCss, processPromisesBatch } = require ( './utils' ) ;
23
23
const React = require ( 'react' ) ;
24
24
const mkdirp = require ( 'mkdirp' ) ;
25
25
const glob = require ( 'glob' ) ;
@@ -54,6 +54,18 @@ async function execute() {
54
54
}
55
55
}
56
56
57
+ async function writeFileAndCreateFolderAsync ( file , content ) {
58
+ await mkdirp . async ( path . dirname ( file ) ) ;
59
+ await fs . writeFile ( file , content ) ;
60
+
61
+ // build extra file for extension-less url if "cleanUrl" siteConfig is true
62
+ if ( siteConfig . cleanUrl && file . indexOf ( 'index.html' ) === - 1 ) {
63
+ const extraFile = file . replace ( / \. h t m l $ / , '/index.html' ) ;
64
+ await mkdirp . async ( path . dirname ( extraFile ) ) ;
65
+ await fs . writeFile ( extraFile , content ) ;
66
+ }
67
+ }
68
+
57
69
console . log ( 'generate.js triggered...' ) ;
58
70
59
71
readMetadata . generateMetadataDocs ( ) ;
@@ -115,10 +127,10 @@ async function execute() {
115
127
const MetadataBlog = require ( '../core/MetadataBlog.js' ) ;
116
128
117
129
let files = glob . sync ( join ( CWD , 'blog' , '**' , '*.*' ) ) ;
118
- files
130
+ const writeFiles = files
119
131
. sort ( )
120
132
. reverse ( )
121
- . forEach ( ( file ) => {
133
+ . map ( async ( file ) => {
122
134
// Why normalize? In case we are on Windows.
123
135
// Remember the nuance of glob: https://www.npmjs.com/package/glob#windows
124
136
const normalizedFile = path . normalize ( file ) ;
@@ -132,9 +144,11 @@ async function execute() {
132
144
return ;
133
145
}
134
146
const targetFile = join ( buildDir , 'blog' , urlPath ) ;
135
- writeFileAndCreateFolder ( targetFile , blogPost ) ;
147
+ await writeFileAndCreateFolderAsync ( targetFile , blogPost ) ;
136
148
} ) ;
137
149
150
+ await processPromiseprocessPromisesBatch ( writeFiles )
151
+
138
152
// create html files for all blog pages (collections of article previews)
139
153
const blogPages = blog . getPagesMarkup ( MetadataBlog . length , siteConfig ) ;
140
154
Object . keys ( blogPages ) . forEach ( ( pagePath ) => {
0 commit comments