@@ -54,6 +54,65 @@ async function generateIndexHtmlFiles(outDir) {
5454 }
5555}
5656
57+ // Copy redirect index.html files to .html ONLY for old release notes paths
58+ // This ensures redirects work with simple HTTP servers like `npm run serve`
59+ // Example: docs/technical-details/release-notes/4.tucker/4.4.0/index.html
60+ // -> docs/technical-details/release-notes/4.tucker/4.4.0.html
61+ async function generateReleaseNotesRedirectHtmlFiles ( outDir ) {
62+ console . log ( 'Post-build: Creating .html redirect files for old release notes paths...' ) ;
63+
64+ const redirectBase = path . join ( outDir , 'docs' , 'technical-details' , 'release-notes' ) ;
65+
66+ try {
67+ await fs . stat ( redirectBase ) ;
68+ } catch {
69+ console . log ( 'Post-build: No release notes redirects found, skipping' ) ;
70+ return ;
71+ }
72+
73+ // Walk through all directories recursively
74+ async function * walkDirs ( dir ) {
75+ const dirents = await fs . readdir ( dir , { withFileTypes : true } ) ;
76+ for ( const dirent of dirents ) {
77+ if ( dirent . isDirectory ( ) ) {
78+ const res = path . resolve ( dir , dirent . name ) ;
79+ yield res ;
80+ yield * walkDirs ( res ) ;
81+ }
82+ }
83+ }
84+
85+ const processedFiles = [ ] ;
86+
87+ for await ( const dirPath of walkDirs ( redirectBase ) ) {
88+ // Check if this directory has an index.html redirect file
89+ const indexPath = path . join ( dirPath , 'index.html' ) ;
90+ try {
91+ const content = await fs . readFile ( indexPath , 'utf8' ) ;
92+ // Check if it's a redirect file (contains meta refresh)
93+ if ( content . includes ( 'meta http-equiv="refresh"' ) ) {
94+ // Create a sibling .html file with the same content
95+ const dirName = path . basename ( dirPath ) ;
96+ const siblingHtmlPath = path . join ( path . dirname ( dirPath ) , `${ dirName } .html` ) ;
97+ await fs . copyFile ( indexPath , siblingHtmlPath ) ;
98+ processedFiles . push ( `${ dirName } /index.html → ${ dirName } .html` ) ;
99+ }
100+ } catch {
101+ // No index.html or other error, skip
102+ }
103+ }
104+
105+ if ( processedFiles . length > 0 ) {
106+ console . log ( `Post-build: Created ${ processedFiles . length } .html redirect files` ) ;
107+ // Uncomment to see details:
108+ // processedFiles.forEach(f => console.log(` - ${f}`));
109+ } else {
110+ console . log ( 'Post-build: No .html redirect files needed' ) ;
111+ }
112+ }
113+
57114// Run the post-processing
58115const buildDir = path . join ( __dirname , '..' , 'build' ) ;
59- generateIndexHtmlFiles ( buildDir ) . catch ( console . error ) ;
116+ generateIndexHtmlFiles ( buildDir )
117+ . then ( ( ) => generateReleaseNotesRedirectHtmlFiles ( buildDir ) )
118+ . catch ( console . error ) ;
0 commit comments