You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by ur...@apache.org on 2022/09/05 12:47:31 UTC

[pulsar-site] branch quick-versions-switch-2 created (now e442be03526)

This is an automated email from the ASF dual-hosted git repository.

urfree pushed a change to branch quick-versions-switch-2
in repository https://gitbox.apache.org/repos/asf/pulsar-site.git


      at e442be03526 docs version quick switch

This branch includes the following new commits:

     new e442be03526 docs version quick switch

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[pulsar-site] 01/01: docs version quick switch

Posted by ur...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

urfree pushed a commit to branch quick-versions-switch-2
in repository https://gitbox.apache.org/repos/asf/pulsar-site.git

commit e442be035268014da043e027dc6b62f9250de0bb
Author: Li Li <ur...@apache.org>
AuthorDate: Mon Sep 5 20:47:20 2022 +0800

    docs version quick switch
    
    Signed-off-by: Li Li <ur...@apache.org>
---
 .../src/theme/DocsVersionDropdownNavbarItem.js     | 60 +++++++++++++---------
 1 file changed, 35 insertions(+), 25 deletions(-)

diff --git a/site2/website-next/src/theme/DocsVersionDropdownNavbarItem.js b/site2/website-next/src/theme/DocsVersionDropdownNavbarItem.js
index 5c20c90ba3d..a0fc0dac6d1 100644
--- a/site2/website-next/src/theme/DocsVersionDropdownNavbarItem.js
+++ b/site2/website-next/src/theme/DocsVersionDropdownNavbarItem.js
@@ -14,17 +14,24 @@ import {
 } from "@docusaurus/plugin-content-docs/client";
 import { useDocsPreferredVersion } from "@docusaurus/theme-common";
 import { translate } from "@docusaurus/Translate";
-// let versions = require("../../versions.json");
-// const _latestVersion = versions[0];
-// versions = [{ name: "current", label: "Master", path: "/docs/next" }].concat(
-//   versions.map((item) => {
-//     return {
-//       label: item,
-//       name: item,
-//       path: item == _latestVersion ? "/docs" : "/docs/" + item,
-//     };
-//   })
-// );
+let versions = require("../../versions.json");
+const _latestVersion = versions[0];
+versions = [{ name: "current", label: "Master", path: "/docs/next" }]
+  .concat(
+    versions.map((item) => {
+      return {
+        label: item,
+        name: item,
+        path: item == _latestVersion ? "/docs" : "/docs/" + item,
+      };
+    })
+  )
+  .slice(0, 5)
+  .concat({
+    name: "others",
+    label: "Other",
+    path: "/versions",
+  });
 
 const getVersionMainDoc = (version) =>
   version.docs.find((doc) => doc.id === version.mainDocId);
@@ -38,33 +45,36 @@ export default function DocsVersionDropdownNavbarItem({
   ...props
 }) {
   const activeDocContext = useActiveDocContext(docsPluginId);
-  // const _versions = useVersions(docsPluginId);
+  const _versions = useVersions(docsPluginId);
   const latestVersion = useLatestVersion(docsPluginId);
   const { preferredVersion, savePreferredVersionName } =
     useDocsPreferredVersion(docsPluginId);
-  const versions = [
-    activeDocContext.activeVersion,
-    {
-      name: "others",
-      label: "Other",
-      path: "/versions",
-    },
-  ];
   function getItems() {
     const versionLinks = versions.map((version) => {
       // We try to link to the same doc, in another version
       // When not possible, fallback to the "main doc" of the version
-      const versionDoc = activeDocContext?.alternateDocVersions[
-        version.name
-      ] || { path: "/docs/" + version.name + "/about" };
-      // getVersionMainDoc(version);
+      const _version =
+        version.name == _latestVersion
+          ? ""
+          : version.name == "current"
+          ? "next/"
+          : version.name + "/";
+      const _docId =
+        activeDocContext.activeDoc.id == "about"
+          ? ""
+          : activeDocContext.activeDoc.id;
+      const versionDoc = {
+        path: "/docs/" + _version + _docId,
+      };
       return {
         isNavLink: true,
         label: version.label,
         to: version.name == "others" ? "/versions" : versionDoc.path,
-        isActive: () => version.name === activeDocContext?.activeVersion.name,
+        isActive: () => version.name === activeDocContext.activeVersion.name,
         onClick: () => {
           savePreferredVersionName(version.name);
+          window.location.href =
+            version.name == "others" ? "/versions" : versionDoc.path;
         },
       };
     });