@seqera/docusaurus-theme-seqera 1.0.13-next.49 → 1.0.14-next.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/theme/DocSidebar/Desktop/Content/VersionSwitcher/index.js +29 -23
- package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +14 -13
- package/lib/theme/NavbarItem/DocsVersionNavbarItem.js +1 -2
- package/lib/theme/hooks/useVersionDropdownConfig.d.ts +13 -0
- package/lib/theme/hooks/useVersionDropdownConfig.js +20 -0
- package/lib/theme/utils/versionHelpers.d.ts +35 -0
- package/lib/theme/utils/versionHelpers.js +46 -0
- package/package.json +1 -1
- package/src/theme/DocSidebar/Desktop/Content/VersionSwitcher/index.tsx +24 -26
- package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +19 -19
- package/src/theme/NavbarItem/DocsVersionNavbarItem.tsx +1 -4
- package/src/theme/hooks/useVersionDropdownConfig.ts +30 -0
- package/src/theme/utils/versionHelpers.ts +63 -0
- package/src/theme-seqera.d.ts +17 -1
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import React, {useRef, useEffect} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
useVersions,
|
|
4
|
-
useDocsVersion,
|
|
5
4
|
useDocsPreferredVersion,
|
|
6
5
|
useActiveDocContext,
|
|
7
6
|
} from '@docusaurus/plugin-content-docs/client';
|
|
8
7
|
import {useAllPluginInstancesData} from '@docusaurus/useGlobalData';
|
|
9
8
|
import {useLocation} from '@docusaurus/router';
|
|
10
9
|
import Link from '@docusaurus/Link';
|
|
10
|
+
import {useVersionDropdownConfig} from '../../../../hooks/useVersionDropdownConfig';
|
|
11
|
+
import {
|
|
12
|
+
getVersionTargetDoc,
|
|
13
|
+
processVersions,
|
|
14
|
+
} from '../../../../utils/versionHelpers';
|
|
11
15
|
/**
|
|
12
16
|
* Detects which docs plugin is active based on the current pathname
|
|
13
17
|
*/
|
|
@@ -24,29 +28,21 @@ function useActiveDocsPlugin() {
|
|
|
24
28
|
}
|
|
25
29
|
return null;
|
|
26
30
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Helper functions to get version documents
|
|
29
|
-
*/
|
|
30
|
-
function getVersionMainDoc(version) {
|
|
31
|
-
return version.docs.find((doc) => doc.id === version.mainDocId);
|
|
32
|
-
}
|
|
33
|
-
function getVersionTargetDoc(version, activeDocContext) {
|
|
34
|
-
// Try to link to the same doc in another version
|
|
35
|
-
// When not possible, fallback to the "main doc" of the version
|
|
36
|
-
return (
|
|
37
|
-
activeDocContext.alternateDocVersions[version.name] ??
|
|
38
|
-
getVersionMainDoc(version)
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
31
|
const VersionSwitcherInner = ({isOpen, setIsOpen, pluginId}) => {
|
|
42
32
|
const dropdownRef = useRef(null);
|
|
43
33
|
// Always call hooks unconditionally - this component only renders when pluginId exists
|
|
44
34
|
const versions = useVersions(pluginId);
|
|
45
35
|
const {savePreferredVersionName} = useDocsPreferredVersion(pluginId);
|
|
46
|
-
const currentVersion = useDocsVersion();
|
|
47
36
|
const activeDocContext = useActiveDocContext(pluginId);
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
const currentVersion = activeDocContext.activeVersion;
|
|
38
|
+
// Get configuration for this plugin's version dropdown
|
|
39
|
+
const config = useVersionDropdownConfig(pluginId);
|
|
40
|
+
// If version dropdown is disabled for this plugin, don't show it
|
|
41
|
+
if (!config.enabled) return null;
|
|
42
|
+
// Process versions based on configuration
|
|
43
|
+
const processedVersions = processVersions(versions, config);
|
|
44
|
+
// Only show version switcher if there are at least 2 versions after processing
|
|
45
|
+
if (!processedVersions || processedVersions.length < 2) return null;
|
|
50
46
|
useEffect(() => {
|
|
51
47
|
const handleClickOutside = (event) => {
|
|
52
48
|
if (dropdownRef.current?.contains(event.target)) return;
|
|
@@ -61,8 +57,13 @@ const VersionSwitcherInner = ({isOpen, setIsOpen, pluginId}) => {
|
|
|
61
57
|
function handleSelectVersion(version) {
|
|
62
58
|
savePreferredVersionName(version);
|
|
63
59
|
}
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
// Update currentVersion label if it's the current version and should be shown with custom label
|
|
61
|
+
const displayCurrentVersion =
|
|
62
|
+
currentVersion?.name === 'current' && config.showCurrent
|
|
63
|
+
? {...currentVersion, label: config.currentLabel}
|
|
64
|
+
: currentVersion;
|
|
65
|
+
const items = processedVersions.filter(
|
|
66
|
+
(version) => version.label !== displayCurrentVersion?.label,
|
|
66
67
|
);
|
|
67
68
|
return (
|
|
68
69
|
<div ref={dropdownRef} className="relative px-4">
|
|
@@ -74,8 +75,11 @@ const VersionSwitcherInner = ({isOpen, setIsOpen, pluginId}) => {
|
|
|
74
75
|
onClick={toggleDropdown}
|
|
75
76
|
className="h-9 w-full flex items-center justify-between px-3 text-sm bg-transparent border-none cursor-pointer relative z-10 text-gray-900 dark:text-white transition-colors hover:bg-gray-100 dark:hover:bg-gray-800">
|
|
76
77
|
<span>
|
|
77
|
-
{
|
|
78
|
-
|
|
78
|
+
{displayCurrentVersion
|
|
79
|
+
? `v${displayCurrentVersion.label}`
|
|
80
|
+
: 'Version'}{' '}
|
|
81
|
+
{displayCurrentVersion &&
|
|
82
|
+
displayCurrentVersion.label === processedVersions[0]?.label
|
|
79
83
|
? '(current)'
|
|
80
84
|
: ''}
|
|
81
85
|
</span>
|
|
@@ -103,7 +107,9 @@ const VersionSwitcherInner = ({isOpen, setIsOpen, pluginId}) => {
|
|
|
103
107
|
to={targetDoc.path}
|
|
104
108
|
className="h-9 w-full flex items-center justify-between px-3 text-sm bg-transparent cursor-pointer text-gray-900 dark:text-white transition-colors hover:bg-gray-100 dark:hover:bg-gray-800 no-underline border-t border-gray-200 dark:border-gray-700 first:border-t-0">
|
|
105
109
|
v{version.label}{' '}
|
|
106
|
-
{version.label ===
|
|
110
|
+
{version.label === processedVersions[0]?.label
|
|
111
|
+
? '(current)'
|
|
112
|
+
: ''}
|
|
107
113
|
</Link>
|
|
108
114
|
</div>
|
|
109
115
|
);
|
|
@@ -9,6 +9,8 @@ import {translate} from '@docusaurus/Translate';
|
|
|
9
9
|
import {useHistorySelector} from '@docusaurus/theme-common';
|
|
10
10
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
11
11
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
12
|
+
import {useVersionDropdownConfig} from '../hooks/useVersionDropdownConfig';
|
|
13
|
+
import {getVersionTargetDoc, processVersions} from '../utils/versionHelpers';
|
|
12
14
|
function getVersionItems(versions, configs) {
|
|
13
15
|
if (configs) {
|
|
14
16
|
// Collect all the versions we have
|
|
@@ -38,17 +40,6 @@ function useVersionItems({docsPluginId, configs}) {
|
|
|
38
40
|
const versions = useVersions(docsPluginId);
|
|
39
41
|
return getVersionItems(versions, configs);
|
|
40
42
|
}
|
|
41
|
-
function getVersionMainDoc(version) {
|
|
42
|
-
return version.docs.find((doc) => doc.id === version.mainDocId);
|
|
43
|
-
}
|
|
44
|
-
function getVersionTargetDoc(version, activeDocContext) {
|
|
45
|
-
// We try to link to the same doc, in another version
|
|
46
|
-
// When not possible, fallback to the "main doc" of the version
|
|
47
|
-
return (
|
|
48
|
-
activeDocContext.alternateDocVersions[version.name] ??
|
|
49
|
-
getVersionMainDoc(version)
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
43
|
// The version item to use for the "dropdown button"
|
|
53
44
|
function useDisplayedVersionItem({docsPluginId, versionItems}) {
|
|
54
45
|
// The order of the candidates matters!
|
|
@@ -72,9 +63,15 @@ export default function DocsVersionDropdownNavbarItem({
|
|
|
72
63
|
const activeDocContext = useActiveDocContext(docsPluginId);
|
|
73
64
|
const {savePreferredVersionName} = useDocsPreferredVersion(docsPluginId);
|
|
74
65
|
const versionItems = useVersionItems({docsPluginId, configs});
|
|
66
|
+
// Get configuration for this plugin's version dropdown
|
|
67
|
+
const config = useVersionDropdownConfig(docsPluginId ?? 'default');
|
|
68
|
+
// If version dropdown is disabled for this plugin, don't show it
|
|
69
|
+
if (!config.enabled) return null;
|
|
70
|
+
// Process version items based on configuration
|
|
71
|
+
const processedVersionItems = processVersions(versionItems, config);
|
|
75
72
|
const displayedVersionItem = useDisplayedVersionItem({
|
|
76
73
|
docsPluginId,
|
|
77
|
-
versionItems,
|
|
74
|
+
versionItems: processedVersionItems,
|
|
78
75
|
});
|
|
79
76
|
function versionItemToLink({version, label}) {
|
|
80
77
|
const targetDoc = getVersionTargetDoc(version, activeDocContext);
|
|
@@ -86,9 +83,13 @@ export default function DocsVersionDropdownNavbarItem({
|
|
|
86
83
|
onClick: () => savePreferredVersionName(version.name),
|
|
87
84
|
};
|
|
88
85
|
}
|
|
86
|
+
// Don't render version dropdown if there's only one version (no versions have been cut yet)
|
|
87
|
+
if (processedVersionItems.length < 2) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
89
90
|
const items = [
|
|
90
91
|
...dropdownItemsBefore,
|
|
91
|
-
...
|
|
92
|
+
...processedVersionItems.map(versionItemToLink),
|
|
92
93
|
...dropdownItemsAfter,
|
|
93
94
|
];
|
|
94
95
|
// Mobile dropdown is handled a bit differently
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {useDocsVersionCandidates} from '@docusaurus/plugin-content-docs/client';
|
|
3
3
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
4
|
-
|
|
5
|
-
version.docs.find((doc) => doc.id === version.mainDocId);
|
|
4
|
+
import {getVersionMainDoc} from '../utils/versionHelpers';
|
|
6
5
|
export default function DocsVersionNavbarItem({
|
|
7
6
|
label: staticLabel,
|
|
8
7
|
to: staticTo,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface VersionDropdownConfig {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
showCurrent: boolean;
|
|
4
|
+
currentLabel: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Hook to get version dropdown configuration for a specific docs plugin
|
|
8
|
+
* Extracts configuration from theme config and applies consistent defaults
|
|
9
|
+
*
|
|
10
|
+
* @param pluginId - The docs plugin ID (e.g., 'default', 'fusion', etc.)
|
|
11
|
+
* @returns Normalized configuration object with defaults applied
|
|
12
|
+
*/
|
|
13
|
+
export declare function useVersionDropdownConfig(pluginId: string): VersionDropdownConfig;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {useThemeConfig} from '@docusaurus/theme-common';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get version dropdown configuration for a specific docs plugin
|
|
4
|
+
* Extracts configuration from theme config and applies consistent defaults
|
|
5
|
+
*
|
|
6
|
+
* @param pluginId - The docs plugin ID (e.g., 'default', 'fusion', etc.)
|
|
7
|
+
* @returns Normalized configuration object with defaults applied
|
|
8
|
+
*/
|
|
9
|
+
export function useVersionDropdownConfig(pluginId) {
|
|
10
|
+
const themeConfig = useThemeConfig();
|
|
11
|
+
// Get configuration for this plugin's version dropdown
|
|
12
|
+
const docsConfig = themeConfig.seqera?.docs;
|
|
13
|
+
const versionDropdownConfig = docsConfig?.versionDropdown?.[pluginId] || {};
|
|
14
|
+
// Apply defaults
|
|
15
|
+
return {
|
|
16
|
+
enabled: versionDropdownConfig.enabled !== false, // default true
|
|
17
|
+
showCurrent: versionDropdownConfig.showCurrent === true, // default false
|
|
18
|
+
currentLabel: versionDropdownConfig.currentLabel || 'Next', // default "Next"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { GlobalVersion, GlobalDoc, ActiveDocContext } from '@docusaurus/plugin-content-docs/client';
|
|
2
|
+
/**
|
|
3
|
+
* Gets the main document for a version
|
|
4
|
+
*/
|
|
5
|
+
export declare function getVersionMainDoc(version: GlobalVersion): GlobalDoc;
|
|
6
|
+
/**
|
|
7
|
+
* Gets the target document for navigation, with fallback to main doc
|
|
8
|
+
* Tries to link to the same doc in another version, falls back to main doc
|
|
9
|
+
*/
|
|
10
|
+
export declare function getVersionTargetDoc(version: GlobalVersion, activeDocContext: ActiveDocContext): GlobalDoc;
|
|
11
|
+
/**
|
|
12
|
+
* Type guard to check if an object has a version property (VersionItem structure)
|
|
13
|
+
*/
|
|
14
|
+
type HasVersion = {
|
|
15
|
+
version: {
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
18
|
+
label: string;
|
|
19
|
+
};
|
|
20
|
+
type HasName = {
|
|
21
|
+
name: string;
|
|
22
|
+
label?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Processes versions based on configuration (filters and relabels)
|
|
26
|
+
* Handles both direct version objects and VersionItem wrappers
|
|
27
|
+
* @param versions - Array of versions or version items to process
|
|
28
|
+
* @param config - Configuration with showCurrent and currentLabel
|
|
29
|
+
* @returns Processed array with filtered and relabeled versions
|
|
30
|
+
*/
|
|
31
|
+
export declare function processVersions<T extends HasVersion | HasName>(versions: T[], config: {
|
|
32
|
+
showCurrent: boolean;
|
|
33
|
+
currentLabel: string;
|
|
34
|
+
}): T[];
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the main document for a version
|
|
3
|
+
*/
|
|
4
|
+
export function getVersionMainDoc(version) {
|
|
5
|
+
return version.docs.find((doc) => doc.id === version.mainDocId);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Gets the target document for navigation, with fallback to main doc
|
|
9
|
+
* Tries to link to the same doc in another version, falls back to main doc
|
|
10
|
+
*/
|
|
11
|
+
export function getVersionTargetDoc(version, activeDocContext) {
|
|
12
|
+
return (
|
|
13
|
+
activeDocContext.alternateDocVersions[version.name] ??
|
|
14
|
+
getVersionMainDoc(version)
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
function hasVersionProperty(item) {
|
|
18
|
+
return item.version !== undefined && typeof item.version.name === 'string';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Processes versions based on configuration (filters and relabels)
|
|
22
|
+
* Handles both direct version objects and VersionItem wrappers
|
|
23
|
+
* @param versions - Array of versions or version items to process
|
|
24
|
+
* @param config - Configuration with showCurrent and currentLabel
|
|
25
|
+
* @returns Processed array with filtered and relabeled versions
|
|
26
|
+
*/
|
|
27
|
+
export function processVersions(versions, config) {
|
|
28
|
+
return versions
|
|
29
|
+
.map((item) => {
|
|
30
|
+
const versionName = hasVersionProperty(item)
|
|
31
|
+
? item.version.name
|
|
32
|
+
: item.name;
|
|
33
|
+
if (versionName === 'current' && config.showCurrent) {
|
|
34
|
+
// Relabel current version with configured label
|
|
35
|
+
return {...item, label: config.currentLabel};
|
|
36
|
+
}
|
|
37
|
+
return item;
|
|
38
|
+
})
|
|
39
|
+
.filter((item) => {
|
|
40
|
+
const versionName = hasVersionProperty(item)
|
|
41
|
+
? item.version.name
|
|
42
|
+
: item.name;
|
|
43
|
+
// If showCurrent is false, exclude the current/Next version
|
|
44
|
+
return config.showCurrent || versionName !== 'current';
|
|
45
|
+
});
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -13,6 +13,8 @@ import type {
|
|
|
13
13
|
import { useAllPluginInstancesData } from "@docusaurus/useGlobalData";
|
|
14
14
|
import { useLocation } from "@docusaurus/router";
|
|
15
15
|
import Link from "@docusaurus/Link";
|
|
16
|
+
import { useVersionDropdownConfig } from "../../../../hooks/useVersionDropdownConfig";
|
|
17
|
+
import { getVersionTargetDoc, processVersions } from "../../../../utils/versionHelpers";
|
|
16
18
|
|
|
17
19
|
interface VersionSwitcherProps {
|
|
18
20
|
isOpen: boolean;
|
|
@@ -42,24 +44,6 @@ function useActiveDocsPlugin(): string | null {
|
|
|
42
44
|
return null;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
/**
|
|
46
|
-
* Helper functions to get version documents
|
|
47
|
-
*/
|
|
48
|
-
function getVersionMainDoc(version: GlobalVersion): GlobalDoc {
|
|
49
|
-
return version.docs.find((doc) => doc.id === version.mainDocId)!;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function getVersionTargetDoc(
|
|
53
|
-
version: GlobalVersion,
|
|
54
|
-
activeDocContext: ActiveDocContext,
|
|
55
|
-
): GlobalDoc {
|
|
56
|
-
// Try to link to the same doc in another version
|
|
57
|
-
// When not possible, fallback to the "main doc" of the version
|
|
58
|
-
return (
|
|
59
|
-
activeDocContext.alternateDocVersions[version.name] ??
|
|
60
|
-
getVersionMainDoc(version)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
47
|
|
|
64
48
|
/**
|
|
65
49
|
* Inner component that handles version switching for a specific plugin
|
|
@@ -74,11 +58,20 @@ const VersionSwitcherInner: React.FC<VersionSwitcherInnerProps> = ({ isOpen, set
|
|
|
74
58
|
// Always call hooks unconditionally - this component only renders when pluginId exists
|
|
75
59
|
const versions = useVersions(pluginId);
|
|
76
60
|
const { savePreferredVersionName } = useDocsPreferredVersion(pluginId);
|
|
77
|
-
const currentVersion = useDocsVersion();
|
|
78
61
|
const activeDocContext = useActiveDocContext(pluginId);
|
|
62
|
+
const currentVersion = activeDocContext.activeVersion;
|
|
63
|
+
|
|
64
|
+
// Get configuration for this plugin's version dropdown
|
|
65
|
+
const config = useVersionDropdownConfig(pluginId);
|
|
66
|
+
|
|
67
|
+
// If version dropdown is disabled for this plugin, don't show it
|
|
68
|
+
if (!config.enabled) return null;
|
|
79
69
|
|
|
80
|
-
//
|
|
81
|
-
|
|
70
|
+
// Process versions based on configuration
|
|
71
|
+
const processedVersions = processVersions(versions, config);
|
|
72
|
+
|
|
73
|
+
// Only show version switcher if there are at least 2 versions after processing
|
|
74
|
+
if (!processedVersions || processedVersions.length < 2) return null;
|
|
82
75
|
|
|
83
76
|
useEffect(() => {
|
|
84
77
|
const handleClickOutside = (event: MouseEvent) => {
|
|
@@ -98,8 +91,13 @@ const VersionSwitcherInner: React.FC<VersionSwitcherInnerProps> = ({ isOpen, set
|
|
|
98
91
|
savePreferredVersionName(version);
|
|
99
92
|
}
|
|
100
93
|
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
// Update currentVersion label if it's the current version and should be shown with custom label
|
|
95
|
+
const displayCurrentVersion = currentVersion?.name === 'current' && config.showCurrent
|
|
96
|
+
? { ...currentVersion, label: config.currentLabel }
|
|
97
|
+
: currentVersion;
|
|
98
|
+
|
|
99
|
+
const items = processedVersions.filter(
|
|
100
|
+
(version) => version.label !== displayCurrentVersion?.label,
|
|
103
101
|
);
|
|
104
102
|
|
|
105
103
|
return (
|
|
@@ -110,8 +108,8 @@ const VersionSwitcherInner: React.FC<VersionSwitcherInnerProps> = ({ isOpen, set
|
|
|
110
108
|
className="h-9 w-full flex items-center justify-between px-3 text-sm bg-transparent border-none cursor-pointer relative z-10 text-gray-900 dark:text-white transition-colors hover:bg-gray-100 dark:hover:bg-gray-800"
|
|
111
109
|
>
|
|
112
110
|
<span>
|
|
113
|
-
{
|
|
114
|
-
{
|
|
111
|
+
{displayCurrentVersion ? `v${displayCurrentVersion.label}` : "Version"}{" "}
|
|
112
|
+
{displayCurrentVersion && displayCurrentVersion.label === processedVersions[0]?.label
|
|
115
113
|
? "(current)"
|
|
116
114
|
: ""}
|
|
117
115
|
</span>
|
|
@@ -140,7 +138,7 @@ const VersionSwitcherInner: React.FC<VersionSwitcherInnerProps> = ({ isOpen, set
|
|
|
140
138
|
className="h-9 w-full flex items-center justify-between px-3 text-sm bg-transparent cursor-pointer text-gray-900 dark:text-white transition-colors hover:bg-gray-100 dark:hover:bg-gray-800 no-underline border-t border-gray-200 dark:border-gray-700 first:border-t-0"
|
|
141
139
|
>
|
|
142
140
|
v{version.label}{" "}
|
|
143
|
-
{version.label ===
|
|
141
|
+
{version.label === processedVersions[0]?.label ? "(current)" : ""}
|
|
144
142
|
</Link>
|
|
145
143
|
</div>
|
|
146
144
|
);
|
|
@@ -19,9 +19,10 @@ import type {
|
|
|
19
19
|
import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
|
|
20
20
|
import type {
|
|
21
21
|
GlobalVersion,
|
|
22
|
-
GlobalDoc,
|
|
23
22
|
ActiveDocContext,
|
|
24
23
|
} from '@docusaurus/plugin-content-docs/client';
|
|
24
|
+
import { useVersionDropdownConfig } from '../hooks/useVersionDropdownConfig';
|
|
25
|
+
import { getVersionTargetDoc, processVersions } from '../utils/versionHelpers';
|
|
25
26
|
|
|
26
27
|
type VersionItem = {
|
|
27
28
|
version: GlobalVersion;
|
|
@@ -73,22 +74,6 @@ function useVersionItems({
|
|
|
73
74
|
return getVersionItems(versions, configs);
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
function getVersionMainDoc(version: GlobalVersion): GlobalDoc {
|
|
77
|
-
return version.docs.find((doc) => doc.id === version.mainDocId)!;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function getVersionTargetDoc(
|
|
81
|
-
version: GlobalVersion,
|
|
82
|
-
activeDocContext: ActiveDocContext,
|
|
83
|
-
): GlobalDoc {
|
|
84
|
-
// We try to link to the same doc, in another version
|
|
85
|
-
// When not possible, fallback to the "main doc" of the version
|
|
86
|
-
return (
|
|
87
|
-
activeDocContext.alternateDocVersions[version.name] ??
|
|
88
|
-
getVersionMainDoc(version)
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
77
|
// The version item to use for the "dropdown button"
|
|
93
78
|
function useDisplayedVersionItem({
|
|
94
79
|
docsPluginId,
|
|
@@ -119,9 +104,19 @@ export default function DocsVersionDropdownNavbarItem({
|
|
|
119
104
|
const activeDocContext = useActiveDocContext(docsPluginId);
|
|
120
105
|
const {savePreferredVersionName} = useDocsPreferredVersion(docsPluginId);
|
|
121
106
|
const versionItems = useVersionItems({docsPluginId, configs});
|
|
107
|
+
|
|
108
|
+
// Get configuration for this plugin's version dropdown
|
|
109
|
+
const config = useVersionDropdownConfig(docsPluginId ?? 'default');
|
|
110
|
+
|
|
111
|
+
// If version dropdown is disabled for this plugin, don't show it
|
|
112
|
+
if (!config.enabled) return null;
|
|
113
|
+
|
|
114
|
+
// Process version items based on configuration
|
|
115
|
+
const processedVersionItems = processVersions(versionItems, config);
|
|
116
|
+
|
|
122
117
|
const displayedVersionItem = useDisplayedVersionItem({
|
|
123
118
|
docsPluginId,
|
|
124
|
-
versionItems,
|
|
119
|
+
versionItems: processedVersionItems,
|
|
125
120
|
});
|
|
126
121
|
|
|
127
122
|
function versionItemToLink({
|
|
@@ -138,9 +133,14 @@ export default function DocsVersionDropdownNavbarItem({
|
|
|
138
133
|
};
|
|
139
134
|
}
|
|
140
135
|
|
|
136
|
+
// Don't render version dropdown if there's only one version (no versions have been cut yet)
|
|
137
|
+
if (processedVersionItems.length < 2) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
141
|
const items: LinkLikeNavbarItemProps[] = [
|
|
142
142
|
...dropdownItemsBefore,
|
|
143
|
-
...
|
|
143
|
+
...processedVersionItems.map(versionItemToLink),
|
|
144
144
|
...dropdownItemsAfter,
|
|
145
145
|
];
|
|
146
146
|
|
|
@@ -4,10 +4,7 @@ import React, {type ReactNode} from 'react';
|
|
|
4
4
|
import {useDocsVersionCandidates} from '@docusaurus/plugin-content-docs/client';
|
|
5
5
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
6
6
|
import type {Props} from '@theme/NavbarItem/DocsVersionNavbarItem';
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
const getVersionMainDoc = (version: GlobalVersion) =>
|
|
10
|
-
version.docs.find((doc) => doc.id === version.mainDocId)!;
|
|
7
|
+
import { getVersionMainDoc } from '../utils/versionHelpers';
|
|
11
8
|
|
|
12
9
|
export default function DocsVersionNavbarItem({
|
|
13
10
|
label: staticLabel,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useThemeConfig } from '@docusaurus/theme-common';
|
|
2
|
+
import type { DocsVersionConfig } from '@seqera/docusaurus-theme-seqera';
|
|
3
|
+
|
|
4
|
+
export interface VersionDropdownConfig {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
showCurrent: boolean;
|
|
7
|
+
currentLabel: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook to get version dropdown configuration for a specific docs plugin
|
|
12
|
+
* Extracts configuration from theme config and applies consistent defaults
|
|
13
|
+
*
|
|
14
|
+
* @param pluginId - The docs plugin ID (e.g., 'default', 'fusion', etc.)
|
|
15
|
+
* @returns Normalized configuration object with defaults applied
|
|
16
|
+
*/
|
|
17
|
+
export function useVersionDropdownConfig(pluginId: string): VersionDropdownConfig {
|
|
18
|
+
const themeConfig = useThemeConfig();
|
|
19
|
+
|
|
20
|
+
// Get configuration for this plugin's version dropdown
|
|
21
|
+
const docsConfig = (themeConfig as any).seqera?.docs as DocsVersionConfig | undefined;
|
|
22
|
+
const versionDropdownConfig = docsConfig?.versionDropdown?.[pluginId] || {};
|
|
23
|
+
|
|
24
|
+
// Apply defaults
|
|
25
|
+
return {
|
|
26
|
+
enabled: versionDropdownConfig.enabled !== false, // default true
|
|
27
|
+
showCurrent: versionDropdownConfig.showCurrent === true, // default false
|
|
28
|
+
currentLabel: versionDropdownConfig.currentLabel || 'Next', // default "Next"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
GlobalVersion,
|
|
3
|
+
GlobalDoc,
|
|
4
|
+
ActiveDocContext,
|
|
5
|
+
} from '@docusaurus/plugin-content-docs/client';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Gets the main document for a version
|
|
9
|
+
*/
|
|
10
|
+
export function getVersionMainDoc(version: GlobalVersion): GlobalDoc {
|
|
11
|
+
return version.docs.find((doc) => doc.id === version.mainDocId)!;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Gets the target document for navigation, with fallback to main doc
|
|
16
|
+
* Tries to link to the same doc in another version, falls back to main doc
|
|
17
|
+
*/
|
|
18
|
+
export function getVersionTargetDoc(
|
|
19
|
+
version: GlobalVersion,
|
|
20
|
+
activeDocContext: ActiveDocContext,
|
|
21
|
+
): GlobalDoc {
|
|
22
|
+
return (
|
|
23
|
+
activeDocContext.alternateDocVersions[version.name] ??
|
|
24
|
+
getVersionMainDoc(version)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Type guard to check if an object has a version property (VersionItem structure)
|
|
30
|
+
*/
|
|
31
|
+
type HasVersion = { version: { name: string }; label: string };
|
|
32
|
+
type HasName = { name: string; label?: string };
|
|
33
|
+
|
|
34
|
+
function hasVersionProperty(item: any): item is HasVersion {
|
|
35
|
+
return item.version !== undefined && typeof item.version.name === 'string';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Processes versions based on configuration (filters and relabels)
|
|
40
|
+
* Handles both direct version objects and VersionItem wrappers
|
|
41
|
+
* @param versions - Array of versions or version items to process
|
|
42
|
+
* @param config - Configuration with showCurrent and currentLabel
|
|
43
|
+
* @returns Processed array with filtered and relabeled versions
|
|
44
|
+
*/
|
|
45
|
+
export function processVersions<T extends HasVersion | HasName>(
|
|
46
|
+
versions: T[],
|
|
47
|
+
config: { showCurrent: boolean; currentLabel: string },
|
|
48
|
+
): T[] {
|
|
49
|
+
return versions
|
|
50
|
+
.map((item) => {
|
|
51
|
+
const versionName = hasVersionProperty(item) ? item.version.name : item.name;
|
|
52
|
+
if (versionName === 'current' && config.showCurrent) {
|
|
53
|
+
// Relabel current version with configured label
|
|
54
|
+
return { ...item, label: config.currentLabel };
|
|
55
|
+
}
|
|
56
|
+
return item;
|
|
57
|
+
})
|
|
58
|
+
.filter((item) => {
|
|
59
|
+
const versionName = hasVersionProperty(item) ? item.version.name : item.name;
|
|
60
|
+
// If showCurrent is false, exclude the current/Next version
|
|
61
|
+
return config.showCurrent || versionName !== 'current';
|
|
62
|
+
});
|
|
63
|
+
}
|
package/src/theme-seqera.d.ts
CHANGED
|
@@ -40,6 +40,22 @@ declare module '@seqera/docusaurus-theme-seqera' {
|
|
|
40
40
|
}
|
|
41
41
|
: U;
|
|
42
42
|
|
|
43
|
+
export interface DocsVersionDropdownConfig {
|
|
44
|
+
/** Whether to show the version dropdown (default: true) */
|
|
45
|
+
enabled?: boolean;
|
|
46
|
+
/** Whether to include the current/Next version in the dropdown (default: false) */
|
|
47
|
+
showCurrent?: boolean;
|
|
48
|
+
/** Label to use for the current version when showCurrent is true (default: "Next") */
|
|
49
|
+
currentLabel?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface DocsVersionConfig {
|
|
53
|
+
/** Configuration for version dropdowns, indexed by plugin ID. Use "default" for the main docs plugin. */
|
|
54
|
+
versionDropdown?: {
|
|
55
|
+
[pluginId: string]: DocsVersionDropdownConfig;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
type OverwriteConfig = {
|
|
44
60
|
seqera: {
|
|
45
61
|
tailwindConfig?: tailwindConfig;
|
|
@@ -51,7 +67,7 @@ declare module '@seqera/docusaurus-theme-seqera' {
|
|
|
51
67
|
footer: {
|
|
52
68
|
socialLinks?: SocialLink[];
|
|
53
69
|
};
|
|
54
|
-
docs?:
|
|
70
|
+
docs?: DocsVersionConfig;
|
|
55
71
|
};
|
|
56
72
|
};
|
|
57
73
|
|