diff --git a/docusaurus.config.js b/docusaurus.config.js index 6453ca5d..9593335c 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -2,9 +2,17 @@ // Note: type annotations allow type checking and IDEs autocompletion const { themes } = require('prism-react-renderer'); +const data = require("./versioned_sidebars/version-1.3.0-sidebars.json"); +import version from './versions.json' +import { getValidPaths } from './utils.js'; + + const lightCodeTheme = themes.github; const darkCodeTheme = themes.dracula; +const validPaths = getValidPaths(data?.version3); +const latestVersion =version[0]; + /** @type {import('@docusaurus/types').Config} */ const config = { title: 'Avesha Docs', @@ -160,7 +168,24 @@ const config = { { id: 'GTM-N7K6NGB', // GTM Container ID } - ] + ], + [ + "@docusaurus/plugin-client-redirects", + { + fromExtensions: ["html", "htm"], + toExtensions: ["exe", "zip"], + redirects: validPaths?.map((path) => ({ + from: `/latest/${path}`, + to: `/${latestVersion}/${path}`, + })), + createRedirects(existingPath) { + if (existingPath.includes("/latest")) { + return [existingPath.replace("/latest", `/${latestVersion}`)]; + } + return undefined; + }, + }, + ], ], themeConfig: /** @type {import('@docusaurus/preset-classic').ThemeConfig} */ diff --git a/package-lock.json b/package-lock.json index 9d9e01c9..6ae0c571 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "dependencies": { "@docusaurus/core": "3.4.0", + "@docusaurus/plugin-client-redirects": "^3.4.0", "@docusaurus/plugin-content-blog": "^3.4.0", "@docusaurus/plugin-google-gtag": "^3.4.0", "@docusaurus/preset-classic": "3.4.0", @@ -2288,6 +2289,29 @@ "react-dom": "*" } }, + "node_modules/@docusaurus/plugin-client-redirects": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/plugin-client-redirects/-/plugin-client-redirects-3.4.0.tgz", + "integrity": "sha512-Pr8kyh/+OsmYCvdZhc60jy/FnrY6flD2TEAhl4rJxeVFxnvvRgEhoaIVX8q9MuJmaQoh6frPk94pjs7/6YgBDQ==", + "dependencies": { + "@docusaurus/core": "3.4.0", + "@docusaurus/logger": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-common": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", + "eta": "^2.2.0", + "fs-extra": "^11.1.1", + "lodash": "^4.17.21", + "tslib": "^2.6.0" + }, + "engines": { + "node": ">=18.0" + }, + "peerDependencies": { + "react": "^18.0.0", + "react-dom": "^18.0.0" + } + }, "node_modules/@docusaurus/plugin-content-blog": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/@docusaurus/plugin-content-blog/-/plugin-content-blog-3.4.0.tgz", diff --git a/package.json b/package.json index d938a6d2..f8b0c92d 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ }, "dependencies": { "@docusaurus/core": "3.4.0", + "@docusaurus/plugin-client-redirects": "^3.4.0", "@docusaurus/plugin-content-blog": "^3.4.0", "@docusaurus/plugin-google-gtag": "^3.4.0", "@docusaurus/preset-classic": "3.4.0", @@ -28,7 +29,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@docusaurus/module-type-aliases": "^3.4.0", + "@docusaurus/module-type-aliases": "^3.4.0", "sass": "^1.69.5" }, "browserslist": { diff --git a/utils.js b/utils.js new file mode 100644 index 00000000..e6d4ea3d --- /dev/null +++ b/utils.js @@ -0,0 +1,31 @@ +function uniquePath(path) { + const segments = path?.split("/").filter(Boolean); + for (let i = 0; i < segments.length; i++) { + if (segments.length === 2 && segments[i] === segments[i + 1]) { + return segments[0] + "/"; + } + } + return path; +} + + +export function getValidPaths(items) { + return items?.flatMap((item) => { + const paths = []; + + if (item?.label) { + if (item.label !== "Overview") { + const formattedTitle = `category/${item?.label.toLowerCase().replace(/\s+/g, "-")}`; + paths.push(formattedTitle); + } + } + + if (item?.items) { + paths.push(...getValidPaths(item?.items)); + } else if (typeof item === "string") { + paths.push(uniquePath(item)); + } + + return paths; + }); +} diff --git a/yarn.lock b/yarn.lock index 463d5eee..5ddccd78 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1360,6 +1360,21 @@ react-helmet-async "*" react-loadable "npm:@docusaurus/react-loadable@6.0.0" +"@docusaurus/plugin-client-redirects@^3.4.0": + version "3.4.0" + resolved "https://registry.npmjs.org/@docusaurus/plugin-client-redirects/-/plugin-client-redirects-3.4.0.tgz" + integrity sha512-Pr8kyh/+OsmYCvdZhc60jy/FnrY6flD2TEAhl4rJxeVFxnvvRgEhoaIVX8q9MuJmaQoh6frPk94pjs7/6YgBDQ== + dependencies: + "@docusaurus/core" "3.4.0" + "@docusaurus/logger" "3.4.0" + "@docusaurus/utils" "3.4.0" + "@docusaurus/utils-common" "3.4.0" + "@docusaurus/utils-validation" "3.4.0" + eta "^2.2.0" + fs-extra "^11.1.1" + lodash "^4.17.21" + tslib "^2.6.0" + "@docusaurus/plugin-content-blog@^3.4.0", "@docusaurus/plugin-content-blog@3.4.0": version "3.4.0" resolved "https://registry.npmjs.org/@docusaurus/plugin-content-blog/-/plugin-content-blog-3.4.0.tgz"