INNER CODE UNIT · JavaScript
createLegacyDocumentationRedirects
namastack/namastack-outbox · namastack-outbox-docs/plugins/canonical-fix-plugin.js:63
function createLegacyDocumentationRedirects(docsDir, outDir, siteUrl, baseUrl, docsPath) {
if (!fs.existsSync(docsDir)) return;
for (const sourceFile of findHtmlFiles(docsDir)) {
const relativePath = path.relative(docsDir, sourceFile);
// /outbox/ is the product page in the new information architecture.
if (relativePath === 'index.html') continue;
const redirectFile = path.join(outDir, 'outbox', relativePath);
const routePath = relativePath.replace(/index\.html$/, '').replace(/\\/g, '/');
const targetPath = `${baseUrl}${docsPath}/${routePath}`;
const canonicalUrl = new URL(targetPath, siteUrl).toString();
fs.mkdirSync(path.dirname(redirectFile), {recursive: true});
fs.writeFileSync(
redirectFile,
[