This is an automated email from the ASF dual-hosted git repository.
tison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-site.git
The following commit(s) were added to refs/heads/main by this push:
new e5bb3782273 Add alias for latest version (#288)
e5bb3782273 is described below
commit e5bb3782273b9aa9911e9910fb540b190c4c4f10
Author: tison <[email protected]>
AuthorDate: Tue Nov 15 18:44:17 2022 +0800
Add alias for latest version (#288)
Signed-off-by: tison <[email protected]>
---
site2/website-next/docusaurus.config.js | 28 +++++++++++------
site2/website-next/preview.sh | 2 +-
.../src/theme/DocsVersionDropdownNavbarItem.js | 36 +++++++---------------
3 files changed, 30 insertions(+), 36 deletions(-)
diff --git a/site2/website-next/docusaurus.config.js
b/site2/website-next/docusaurus.config.js
index 66b7ff8adbe..791eadc1d36 100644
--- a/site2/website-next/docusaurus.config.js
+++ b/site2/website-next/docusaurus.config.js
@@ -5,7 +5,7 @@ const linkifyRegex = require("./plugins/remark-linkify-regex");
const versions = require("./versions.json");
const versionsMap = {
..._.keyBy(
- versions.slice(1).map((item) => {
+ versions.map((item) => {
return {
label: item,
path: item,
@@ -152,7 +152,7 @@ module.exports = {
navbar: {
title: "",
logo: {
- alt: "pulasr logo",
+ alt: "pulsar logo",
src: "img/logo.svg",
},
items: [
@@ -177,7 +177,7 @@ module.exports = {
],
},
{
- href: "/docs/",
+ href: `/docs/${versions[0]}`,
position: "right",
label: "Docs",
},
@@ -398,13 +398,21 @@ module.exports = {
],
],
plugins: [
- // [
- // "client-redirects",
- // /** @type {import('@docusaurus/plugin-client-redirects').Options} */
- // ({
- // fromExtensions: ["html"],
- // }),
- // ],
+ [
+ '@docusaurus/plugin-client-redirects',
+ /** @type {import('@docusaurus/plugin-client-redirects').Options} */
+ {
+ createRedirects(existingPath) {
+ const latestVersion = versions[0];
+ if (existingPath.includes(`/docs/${latestVersion}`)) {
+ return [
+ existingPath.replace(`/docs/${latestVersion}`, '/docs/'),
+ ];
+ }
+ return undefined;
+ },
+ },
+ ],
"./postcss-tailwind-loader",
[
'@docusaurus/plugin-content-docs',
diff --git a/site2/website-next/preview.sh b/site2/website-next/preview.sh
index 8d332813d4a..3ec43eebb98 100755
--- a/site2/website-next/preview.sh
+++ b/site2/website-next/preview.sh
@@ -8,4 +8,4 @@ BUILD_VERSIONS=$BUILD_VERSIONS"]"
echo $BUILD_VERSIONS >.build-versions.json
yarn install
-yarn start
\ No newline at end of file
+yarn start
diff --git a/site2/website-next/src/theme/DocsVersionDropdownNavbarItem.js
b/site2/website-next/src/theme/DocsVersionDropdownNavbarItem.js
index d0fbd614815..628908a73bc 100644
--- a/site2/website-next/src/theme/DocsVersionDropdownNavbarItem.js
+++ b/site2/website-next/src/theme/DocsVersionDropdownNavbarItem.js
@@ -4,25 +4,21 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
-import React, { version } from "react";
+import React from "react";
import DefaultNavbarItem from "@theme/NavbarItem/DefaultNavbarItem";
import DropdownNavbarItem from "@theme/NavbarItem/DropdownNavbarItem";
-import {
- useVersions,
- useLatestVersion,
- useActiveDocContext,
-} from "@docusaurus/plugin-content-docs/client";
-import { useDocsPreferredVersion } from "@docusaurus/theme-common";
-import { translate } from "@docusaurus/Translate";
+import {useActiveDocContext, useLatestVersion,} 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: "Next", path: "/docs/next" }]
.concat(
versions.map((item) => {
return {
label: item,
name: item,
- path: item == _latestVersion ? "/docs" : "/docs/" + item,
+ path: "/docs/" + item,
};
})
)
@@ -45,7 +41,6 @@ export default function DocsVersionDropdownNavbarItem({
...props
}) {
const activeDocContext = useActiveDocContext(docsPluginId);
- const _versions = useVersions(docsPluginId);
const latestVersion = useLatestVersion(docsPluginId);
const { preferredVersion, savePreferredVersionName } =
useDocsPreferredVersion(docsPluginId);
@@ -53,28 +48,19 @@ export default function DocsVersionDropdownNavbarItem({
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 _version =
- version.name == _latestVersion
- ? ""
- : version.name == "current"
- ? "next/"
- : version.name + "/";
- const _docId =
- activeDocContext.activeDoc.id == "about"
- ? ""
- : activeDocContext.activeDoc.id;
+ const _version = version.name === "current" ? "/next" : "/" +
version.name;
+ const _docId = activeDocContext.activeDoc.id === "about" ? "/" :
activeDocContext.activeDoc.id;
const versionDoc = {
- path: "/docs/" + _version + _docId,
+ path: "/docs" + _version + _docId,
};
return {
isNavLink: true,
label: version.label,
- to: "", //iiversion.name == "others" ? "/versions" : versionDoc.path,
+ to: "",
isActive: () => version.name === activeDocContext.activeVersion.name,
onClick: () => {
savePreferredVersionName(version.name);
- window.location.href =
- version.name == "others" ? "/versions" : versionDoc.path;
+ window.location.href = version.name === "others" ? "/versions" :
versionDoc.path;
},
};
});