Skip to content

Commit

Permalink
Add alias for latest version (#288)
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun authored Nov 15, 2022
1 parent 966a642 commit e5bb378
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
28 changes: 18 additions & 10 deletions site2/website-next/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -152,7 +152,7 @@ module.exports = {
navbar: {
title: "",
logo: {
alt: "pulasr logo",
alt: "pulsar logo",
src: "img/logo.svg",
},
items: [
Expand All @@ -177,7 +177,7 @@ module.exports = {
],
},
{
href: "/docs/",
href: `/docs/${versions[0]}`,
position: "right",
label: "Docs",
},
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion site2/website-next/preview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ BUILD_VERSIONS=$BUILD_VERSIONS"]"
echo $BUILD_VERSIONS >.build-versions.json

yarn install
yarn start
yarn start
36 changes: 11 additions & 25 deletions site2/website-next/src/theme/DocsVersionDropdownNavbarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
})
)
Expand All @@ -45,36 +41,26 @@ export default function DocsVersionDropdownNavbarItem({
...props
}) {
const activeDocContext = useActiveDocContext(docsPluginId);
const _versions = useVersions(docsPluginId);
const latestVersion = useLatestVersion(docsPluginId);
const { preferredVersion, savePreferredVersionName } =
useDocsPreferredVersion(docsPluginId);
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 _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;
},
};
});
Expand Down

0 comments on commit e5bb378

Please sign in to comment.