@@ -19,7 +19,7 @@ async function execute() {
1919 const fs = require ( 'fs-extra' ) ;
2020 const readMetadata = require ( './readMetadata.js' ) ;
2121 const path = require ( 'path' ) ;
22- const { minifyCss, isSeparateCss, autoPrefixCss} = require ( './utils' ) ;
22+ const { minifyCss, isSeparateCss, autoPrefixCss, processPromisesBatch } = require ( './utils' ) ;
2323 const React = require ( 'react' ) ;
2424 const mkdirp = require ( 'mkdirp' ) ;
2525 const glob = require ( 'glob' ) ;
@@ -54,6 +54,18 @@ async function execute() {
5454 }
5555 }
5656
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+
5769 console . log ( 'generate.js triggered...' ) ;
5870
5971 readMetadata . generateMetadataDocs ( ) ;
@@ -115,10 +127,10 @@ async function execute() {
115127 const MetadataBlog = require ( '../core/MetadataBlog.js' ) ;
116128
117129 let files = glob . sync ( join ( CWD , 'blog' , '**' , '*.*' ) ) ;
118- files
130+ const writeFiles = files
119131 . sort ( )
120132 . reverse ( )
121- . forEach ( ( file ) => {
133+ . map ( async ( file ) => {
122134 // Why normalize? In case we are on Windows.
123135 // Remember the nuance of glob: https://www.npmjs.com/package/glob#windows
124136 const normalizedFile = path . normalize ( file ) ;
@@ -132,9 +144,11 @@ async function execute() {
132144 return ;
133145 }
134146 const targetFile = join ( buildDir , 'blog' , urlPath ) ;
135- writeFileAndCreateFolder ( targetFile , blogPost ) ;
147+ await writeFileAndCreateFolderAsync ( targetFile , blogPost ) ;
136148 } ) ;
137149
150+ await processPromiseprocessPromisesBatch ( writeFiles )
151+
138152 // create html files for all blog pages (collections of article previews)
139153 const blogPages = blog . getPagesMarkup ( MetadataBlog . length , siteConfig ) ;
140154 Object . keys ( blogPages ) . forEach ( ( pagePath ) => {
0 commit comments