diff --git a/docusaurus.config.js b/docusaurus.config.js index c1c1eca294..b1d3cc4f04 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -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). @@ -31,6 +31,8 @@ PRODUCTS.forEach(product => { }); }); +const latestVersionMap = getLatestVersionUrlMap(); + /** @type {import('@docusaurus/types').Config} */ const config = { title: 'Netwrix Product Documentation', @@ -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 diff --git a/src/config/products.js b/src/config/products.js index f64188a1dd..2aee811ba1 100644 --- a/src/config/products.js +++ b/src/config/products.js @@ -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) */