@@ -7,26 +7,26 @@ const CopyMarkdownImageWebpackPlugin = require('copy-markdown-image-webpack-plug
77const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' )
88const PrerenderSPAPlugin = require ( 'crd-prerender-spa-plugin' )
99const { generateSiteMap } = require ( 'crd-generator-sitemap' )
10- // const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
11- // const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
1210const fs = require ( 'fs-extra' )
1311const { defaultHTMLPath, docsBuildDist } = require ( 'crd-utils' )
1412const { getDocsConfig } = require ( 'crd-utils' )
1513const config = require ( './webpack.config' )
1614const paths = require ( './path' )
17- const getPrerenderRoutes = require ( './getPrerenderRoutes' )
15+ const { getPrerenderRoutes, getDirTree } = require ( './getPrerenderRoutes' )
1816
1917const Renderer = PrerenderSPAPlugin . PuppeteerRenderer
2018
2119module . exports = function ( cmd ) {
2220 const docsConfig = getDocsConfig ( )
21+ const dirTree = getDirTree ( cmd )
22+ const routes = getPrerenderRoutes ( dirTree )
23+
2324 config . mode = 'production'
2425 config . entry = [ paths . appIndexJs ]
2526 // config.output.filename = 'js/[hash:8].js'
2627 config . output . chunkFilename = 'js/[name].[hash:8].js'
2728 config . output . publicPath = docsConfig . repo ? `/${ docsConfig . repo } /` : '/'
2829 config . output . path = docsConfig . repo ? `${ docsBuildDist } /${ docsConfig . repo } ` : docsBuildDist
29-
3030 config . module . rules = config . module . rules . map ( ( item ) => {
3131 if ( item . oneOf ) {
3232 const loaders = [ ]
@@ -121,8 +121,6 @@ module.exports = function (cmd) {
121121 // ],
122122 }
123123
124- const routes = getPrerenderRoutes ( cmd )
125-
126124 config . plugins = config . plugins . concat ( [
127125 new webpack . DefinePlugin ( {
128126 env : JSON . stringify ( 'prod' ) ,
@@ -169,8 +167,11 @@ module.exports = function (cmd) {
169167 // not use fs.move here or it'll throw error in github action
170168 await fs . copy ( `${ docsBuildDist } /${ docsConfig . repo } ` , docsBuildDist )
171169 await fs . remove ( `${ docsBuildDist } /${ docsConfig . repo } ` )
170+ const defaultPath = ( dirTree . find ( data => data . name === 'README.md' )
171+ && dirTree . find ( data => data . name === 'README.md' ) . mdconf
172+ && dirTree . find ( data => data . name === 'README.md' ) . mdconf . abbrlink ) || 'README'
172173 // move README as root index.html
173- await fs . copy ( `${ docsBuildDist } /README /index.html` , `${ docsBuildDist } /index.html` )
174+ await fs . copy ( `${ docsBuildDist } /${ defaultPath } /index.html` , `${ docsBuildDist } /index.html` )
174175 console . log ( '✅ generate prerender file success!' )
175176 if ( docsConfig . seo ) {
176177 if ( docsConfig . seo . google ) {
0 commit comments