From e0e05d0a2ec3a993fd088cb06339fa0d4c992c58 Mon Sep 17 00:00:00 2001 From: Alireza Date: Tue, 22 Jun 2021 22:30:33 -0400 Subject: [PATCH] feat: Add nav links --- platform/docs/docusaurus.config.js | 9 +- .../src/theme/DocVersionSuggestions/index.js | 131 ++++++++++++++++++ 2 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 platform/docs/src/theme/DocVersionSuggestions/index.js diff --git a/platform/docs/docusaurus.config.js b/platform/docs/docusaurus.config.js index 19a4ea989..7ccd7d2f9 100644 --- a/platform/docs/docusaurus.config.js +++ b/platform/docs/docusaurus.config.js @@ -265,12 +265,15 @@ const isI18nStaging = process.env.I18N_STAGING === 'true'; }, items: [ { - type: 'doc', position: 'left', + to: '/', + activeBaseRegex: '^(/next/|/)$', docId: 'Introduction', - label: 'Docs', + label: 'Docs & API', }, - // {to: 'blog', label: 'Blog', position: 'left'}, + { to: 'next/userManuals/index', label: 'User Manuals', position: 'left' }, + { to: 'next/help', activeBaseRegex: '(^/help$)|(/next/help)', label: 'Help', position: 'right' }, + { to: 'https://react.ohif.org/', label: 'UI Component Library', position: 'left' }, // {to: 'showcase', label: 'Showcase', position: 'left'}, // right { diff --git a/platform/docs/src/theme/DocVersionSuggestions/index.js b/platform/docs/src/theme/DocVersionSuggestions/index.js new file mode 100644 index 000000000..82cde75dd --- /dev/null +++ b/platform/docs/src/theme/DocVersionSuggestions/index.js @@ -0,0 +1,131 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import React from 'react'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; +import Link from '@docusaurus/Link'; +import Translate from '@docusaurus/Translate'; +import { + useActivePlugin, + useActiveVersion, + useDocVersionSuggestions, +} from '@theme/hooks/useDocs'; +import { useDocsPreferredVersion } from '@docusaurus/theme-common'; + +function UnreleasedVersionLabel({ siteTitle, versionLabel }) { + return ( + {versionLabel}, + latestVersionLink: ( + + + + docs + + + + ), + }}> + { + 'This is unreleased documentation for {siteTitle} {versionLabel} version. For up-to-date documentation, see OHIF v2.0 {latestVersionLink}.' + } + + ); +} + +function UnmaintainedVersionLabel({ siteTitle, versionLabel }) { + return ( + {versionLabel}, + }}> + { + 'This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.' + } + + ); +} + +function LatestVersionSuggestionLabel({ versionLabel, to, onClick }) { + return ( + + + + latest version + + + + ), + }}> + { + 'For up-to-date documentation, see the {latestVersionLink} ({versionLabel}).' + } + + ); +} + +const getVersionMainDoc = (version) => + version.docs.find((doc) => doc.id === version.mainDocId); + +function DocVersionSuggestions() { + const { + siteConfig: { title: siteTitle }, + } = useDocusaurusContext(); + const { pluginId } = useActivePlugin({ + failfast: true, + }); + const { savePreferredVersionName } = useDocsPreferredVersion(pluginId); + const activeVersion = useActiveVersion(pluginId); + const { + latestDocSuggestion, + latestVersionSuggestion, + } = useDocVersionSuggestions(pluginId); // No suggestion to be made + + if (!latestVersionSuggestion) { + return <>; + } // try to link to same doc in latest version (not always possible) + // fallback to main doc of latest version + + const latestVersionSuggestedDoc = + latestDocSuggestion ?? getVersionMainDoc(latestVersionSuggestion); + return ( +
+
+ {activeVersion.name === 'current' ? ( + + ) : ( + + )} +
+ +
+ ); +} + +export default DocVersionSuggestions;