11// for dev, run:
22// npm run clean && npm run bundle && npm run generate:htmls
3- // npm run rsbuild preview
3+ // npm run bundle: preview
44
55import { join } from "path" ;
66import { readFileSync , writeFileSync , mkdirSync } from "fs" ;
@@ -24,13 +24,14 @@ const SKIP_ROOT_HTML = process.env.SKIP_ROOT_HTML === "true";
2424console . log ( `generating ${ allPages . length } html files ...` ) ;
2525
2626allPages . forEach ( ( pageInfo ) => {
27- const pathName = pageInfo . uri ;
28- const outputHtmlDir = join ( distFolder , pathName ) ;
29- const outputHtmlPath = join ( outputHtmlDir , "index.html" ) ;
30- if ( SKIP_ROOT_HTML && outputHtmlPath === indexHtmlPath ) {
31- console . log ( `skipping root html: ${ outputHtmlPath } ` ) ;
27+ let pathName = pageInfo . uri . replace ( / \/ $ / , "" ) ;
28+ pathName = `${ pathName || "index" } .html` ;
29+ if ( SKIP_ROOT_HTML && pathName === "index.html" ) {
30+ console . log ( `skipping root html` ) ;
3231 return ;
3332 }
33+ const outputHtmlPath = join ( distFolder , pathName ) ;
34+ const outputHtmlParentDir = join ( outputHtmlPath , ".." ) ;
3435
3536 let newHtml = indexHtml ;
3637 newHtml = newHtml . replace (
@@ -58,7 +59,7 @@ allPages.forEach((pageInfo) => {
5859 newHtml = newHtml . replace ( / { { ogImage} } / g, pageInfo . ogImage ) ;
5960 newHtml = newHtml . replace ( / { { sentryOrigin} } / g, `https://${ SENTRY_ORIGIN } ` ) ;
6061
61- mkdirSync ( outputHtmlDir , { recursive : true } ) ;
62+ mkdirSync ( outputHtmlParentDir , { recursive : true } ) ;
6263 writeFileSync ( outputHtmlPath , newHtml ) ;
6364
6465 console . log ( outputHtmlPath , "✅" ) ;
0 commit comments