Skip to content

Commit

Permalink
feat(): added latest alias to redirect to latest version in place o…
Browse files Browse the repository at this point in the history
…f version number. (#217)

* feat(): introduced alias to redirect to latest version

* fix(): routing of uninstall and uninstall-kubeslice file

* feat(): redirected the ctaegory type routes

* cleanup
  • Loading branch information
Sandesh-d12 authored Oct 17, 2024
1 parent f17d231 commit 488150f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 2 deletions.
27 changes: 26 additions & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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} */
Expand Down
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
31 changes: 31 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
@@ -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;
});
}
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,21 @@
react-helmet-async "*"
react-loadable "npm:@docusaurus/[email protected]"

"@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/[email protected]":
version "3.4.0"
resolved "https://registry.npmjs.org/@docusaurus/plugin-content-blog/-/plugin-content-blog-3.4.0.tgz"
Expand Down

0 comments on commit 488150f

Please sign in to comment.