Skip to content
15 changes: 14 additions & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { readFileSync, existsSync } from 'fs';
import { resolve } from 'path';
import { themes as prismThemes } from 'prism-react-renderer';
import { generateDocusaurusPlugins, generateNavbarDropdowns, PRODUCTS, versionToUrl, getDefaultVersion } from './src/config/products.js';
import { generateDocusaurusPlugins, generateNavbarDropdowns, PRODUCTS, versionToUrl, getDefaultVersion, getLatestVersionUrlMap } from './src/config/products.js';

// Strip TypeScript syntax from a generated sidebar.ts and return its apisidebar array.
// Returns [] if the file doesn't exist yet (before gen-api-docs has run).
Expand All @@ -31,6 +31,8 @@ PRODUCTS.forEach(product => {
});
});

const latestVersionMap = getLatestVersionUrlMap();

/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'Netwrix Product Documentation',
Expand Down Expand Up @@ -152,6 +154,17 @@ const config = {
to: `/${targetPath}`,
};
}),
createRedirects(existingPath) {
for (const [productId, latestUrlVersion] of Object.entries(latestVersionMap)) {
const versionedPrefix = `/docs/${productId}/${latestUrlVersion}/`;
if (existingPath.startsWith(versionedPrefix)) {
const rest = existingPath.slice(versionedPrefix.length).replace(/\/$/, '');
if (!rest) return undefined;
return [`/docs/${productId}/${rest}`];
}
}
return undefined;
},
},
],
// Generate all product documentation plugins from centralized configuration
Expand Down
19 changes: 19 additions & 0 deletions src/config/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,25 @@ export function getDefaultVersion(product) {
return product.versions.find((v) => v.isLatest) || product.versions[0];
}

/**
* Build a map of product ID → latest URL-version string.
* Used by the evergreen-links redirect config to generate version-less aliases.
* Skips single-version 'current' products (their URLs are already version-less).
*/
export function getLatestVersionUrlMap() {
const map = {};
for (const product of PRODUCTS) {
if (product.versions.length === 1 && product.versions[0].version === 'current') continue;
const latest = getDefaultVersion(product);
if (!latest) continue;
const urlVersion = latest.customRoutePath
? latest.customRoutePath.split('/').pop()
: versionToUrl(latest.version);
map[product.id] = urlVersion;
}
return map;
}

/**
* Create product map for route matching (used by ProductMetaTags)
*/
Expand Down
Loading