Skip to content

Commit e5ab4d2

Browse files
authored
Merge pull request #329 from HarperDB/comprehensive-releasenotes-redir
redirects for old release notes pattern
2 parents 34d9ca0 + cc0c26d commit e5ab4d2

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

redirects.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,36 @@ export function createRedirects(existingPath: string, basePath: string = ''): st
194194
// Extract the path after /release-notes/
195195
const subpath = existingPath.replace('/release-notes/', '');
196196

197+
// Handle old version naming (4.tucker -> v4-tucker, etc.)
198+
let oldSubpath = subpath;
199+
const versionMap: Record<string, string> = {
200+
'v1-alby': '1.alby',
201+
'v2-penny': '2.penny',
202+
'v3-monkey': '3.monkey',
203+
'v4-tucker': '4.tucker',
204+
};
205+
206+
// Check if the path starts with a new version name and convert to old format
207+
for (const [newName, oldName] of Object.entries(versionMap)) {
208+
if (subpath.startsWith(`${newName}/`) || subpath === newName) {
209+
oldSubpath = subpath.replace(newName, oldName);
210+
break;
211+
}
212+
}
213+
197214
// Add redirects from current version docs (4.6 is served at /docs/)
198215
redirects.push(`/docs/technical-details/release-notes/${subpath}`);
216+
if (oldSubpath !== subpath) {
217+
redirects.push(`/docs/technical-details/release-notes/${oldSubpath}`);
218+
}
199219

200220
// Also redirect from all versioned docs paths
201221
const versions = ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6'];
202222
for (const version of versions) {
203223
redirects.push(`/docs/${version}/technical-details/release-notes/${subpath}`);
224+
if (oldSubpath !== subpath) {
225+
redirects.push(`/docs/${version}/technical-details/release-notes/${oldSubpath}`);
226+
}
204227
}
205228
}
206229

scripts/postbuild.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
58115
const 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

Comments
 (0)