Skip to content

Commit 0935557

Browse files
authored
Hide unsupported from versions dropdown menu; add single page for navigating to unsupported versions (#808)
* Swizzle version dropdown component * Add unsupported versions; remove front-matter config * Hide unsupported versions from version dropdown menu * Create unsupported-versions.mdx * Hide unsupported Japanese versions of docs
1 parent aadf7c0 commit 0935557

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
---
3+
4+
# サポートされていないバージョン
5+
6+
import TranslationBanner from '/src/components/_translation-ja-jp.mdx';
7+
8+
<TranslationBanner />
9+
10+
ScalarDB の次のバージョンはサポートされなくなりました。
11+
12+
- [ScalarDB 3.8](/docs/3.8/)
13+
- [ScalarDB 3.7](/docs/3.7/)
14+
- [ScalarDB 3.6](/docs/3.6/)
15+
- [ScalarDB 3.5](/docs/3.5/)
16+
- [ScalarDB 3.4](/docs/3.4/)

src/pages/unsupported-versions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
2-
toc: false
32
---
43

54
# Unsupported Versions
65

76
The following versions of ScalarDB are no longer supported:
87

8+
- [ScalarDB 3.8](/docs/3.8/)
9+
- [ScalarDB 3.7](/docs/3.7/)
910
- [ScalarDB 3.6](/docs/3.6/)
1011
- [ScalarDB 3.5](/docs/3.5/)
1112
- [ScalarDB 3.4](/docs/3.4/)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import React from 'react';
2+
import {
3+
useVersions,
4+
useActiveDocContext,
5+
useDocsVersionCandidates,
6+
useDocsPreferredVersion,
7+
} from '@docusaurus/plugin-content-docs/client';
8+
import {translate} from '@docusaurus/Translate';
9+
import {useLocation} from '@docusaurus/router';
10+
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
11+
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
12+
13+
function getVersionMainDoc(version) {
14+
return version.docs.find((doc) => doc.id === version.mainDocId);
15+
}
16+
17+
function getVersionTargetDoc(version, activeDocContext) {
18+
// We try to link to the same doc, in another version
19+
// When not possible, fallback to the "main doc" of the version
20+
return (
21+
activeDocContext.alternateDocVersions[version.name] ??
22+
getVersionMainDoc(version)
23+
);
24+
}
25+
26+
export default function DocsVersionDropdownNavbarItem({
27+
mobile,
28+
docsPluginId,
29+
dropdownActiveClassDisabled,
30+
dropdownItemsBefore = [],
31+
dropdownItemsAfter = [],
32+
...props
33+
}) {
34+
const {search, hash} = useLocation();
35+
const activeDocContext = useActiveDocContext(docsPluginId);
36+
const versions = useVersions(docsPluginId);
37+
const {savePreferredVersionName} = useDocsPreferredVersion(docsPluginId);
38+
39+
// Filter out versions with "unsupported" or "サポートされていない" in the label
40+
const supportedVersions = versions.filter((version) => {
41+
const label = version.label.toLowerCase();
42+
return (
43+
!label.includes('(unsupported)') &&
44+
!label.includes('(サポートされていない)')
45+
);
46+
});
47+
48+
function versionToLink(version) {
49+
const targetDoc = getVersionTargetDoc(version, activeDocContext);
50+
return {
51+
label: version.label,
52+
// preserve ?search#hash suffix on version switches
53+
to: `${targetDoc.path}${search}${hash}`,
54+
isActive: () => version === activeDocContext.activeVersion,
55+
onClick: () => savePreferredVersionName(version.name),
56+
};
57+
}
58+
59+
const items = [
60+
...dropdownItemsBefore,
61+
...supportedVersions.map(versionToLink),
62+
...dropdownItemsAfter,
63+
{
64+
label: translate({
65+
id: 'navbar.unsupportedVersions',
66+
message: 'Unsupported Versions',
67+
}),
68+
to: '/unsupported-versions',
69+
},
70+
];
71+
72+
const dropdownVersion = useDocsVersionCandidates(docsPluginId)[0];
73+
// Mobile dropdown is handled a bit differently
74+
const dropdownLabel =
75+
mobile && items.length > 1
76+
? translate({
77+
id: 'theme.navbar.mobileVersionsDropdown.label',
78+
message: 'Versions',
79+
description:
80+
'The label for the navbar versions dropdown on mobile view',
81+
})
82+
: dropdownVersion.label;
83+
84+
const dropdownTo =
85+
mobile && items.length > 1
86+
? undefined
87+
: getVersionTargetDoc(dropdownVersion, activeDocContext).path;
88+
// We don't want to render a version dropdown with 0 or 1 item. If we build
89+
// the site with a single docs version (onlyIncludeVersions: ['1.0.0']),
90+
// We'd rather render a button instead of a dropdown
91+
92+
if (items.length <= 1) {
93+
return (
94+
<DefaultNavbarItem
95+
{...props}
96+
mobile={mobile}
97+
label={dropdownLabel}
98+
to={dropdownTo}
99+
isActive={dropdownActiveClassDisabled ? () => false : undefined}
100+
/>
101+
);
102+
}
103+
104+
return (
105+
<DropdownNavbarItem
106+
{...props}
107+
mobile={mobile}
108+
label={dropdownLabel}
109+
to={dropdownTo}
110+
items={items}
111+
isActive={dropdownActiveClassDisabled ? () => false : undefined}
112+
/>
113+
);
114+
}

0 commit comments

Comments
 (0)