1
1
// for dev, run:
2
2
// npm run clean && npm run bundle && npm run generate:htmls
3
- // npm run rsbuild preview
3
+ // npm run bundle: preview
4
4
5
5
import { join } from "path" ;
6
6
import { readFileSync , writeFileSync , mkdirSync } from "fs" ;
@@ -24,13 +24,14 @@ const SKIP_ROOT_HTML = process.env.SKIP_ROOT_HTML === "true";
24
24
console . log ( `generating ${ allPages . length } html files ...` ) ;
25
25
26
26
allPages . 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` ) ;
32
31
return ;
33
32
}
33
+ const outputHtmlPath = join ( distFolder , pathName ) ;
34
+ const outputHtmlParentDir = join ( outputHtmlPath , ".." ) ;
34
35
35
36
let newHtml = indexHtml ;
36
37
newHtml = newHtml . replace (
@@ -58,7 +59,7 @@ allPages.forEach((pageInfo) => {
58
59
newHtml = newHtml . replace ( / { { ogImage} } / g, pageInfo . ogImage ) ;
59
60
newHtml = newHtml . replace ( / { { sentryOrigin} } / g, `https://${ SENTRY_ORIGIN } ` ) ;
60
61
61
- mkdirSync ( outputHtmlDir , { recursive : true } ) ;
62
+ mkdirSync ( outputHtmlParentDir , { recursive : true } ) ;
62
63
writeFileSync ( outputHtmlPath , newHtml ) ;
63
64
64
65
console . log ( outputHtmlPath , "✅" ) ;
0 commit comments