Skip to content

Commit 66ae9db

Browse files
authored
Changes in documentation version's drop-down (handsontable#10079)
1 parent 0e737b9 commit 66ae9db

File tree

6 files changed

+69
-45
lines changed

6 files changed

+69
-45
lines changed

docs/.vuepress/enhanceApp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default async({ router, siteData, isServer }) => {
8383

8484
page.versions = docsData.versions;
8585
page.latestVersion = docsData.latestVersion;
86+
page.versionsWithPatches = new Map(docsData.versionsWithPatches);
8687
});
8788

8889
router.options.scrollBehavior = function(to, from, savedPosition) {

docs/.vuepress/plugins/dump-docs-data/docs-versions.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ const { Octokit } = require('@octokit/rest');
99
const { logger } = require('@vuepress/shared-utils');
1010

1111
/**
12-
* Min Docs version that is listed in the Docs version dropdown menu.
12+
* Min docs version that is used for creating canonicals.
1313
*/
1414
const MIN_DOCS_VERSION = '9.0';
15+
/**
16+
* Max number of minors displayed in the drop-down.
17+
*/
18+
const MAX_MINORS_COUNT = 6;
1519

1620
/**
1721
* Reads the list of Docs versions from the latest Docs image.
@@ -32,7 +36,6 @@ async function readFromDocsLatest() {
3236
*/
3337
async function readFromGitHub() {
3438
const octokit = new Octokit();
35-
let versions = [];
3639

3740
const releases = await octokit.rest.repos
3841
.listReleases({
@@ -46,15 +49,31 @@ async function readFromGitHub() {
4649
}
4750

4851
const tagsSet = new Set();
52+
const minorsToPatches = new Map();
4953

5054
releases.data
5155
.map(item => item.tag_name)
5256
.sort((a, b) => semver.rcompare(a, b))
53-
.forEach(tag => tagsSet.add(`${semver.parse(tag).major}.${semver.parse(tag).minor}`));
57+
.forEach((tag) => {
58+
const minorVersion = `${semver.parse(tag).major}.${semver.parse(tag).minor}`;
59+
const patchVersion = `${minorVersion}.${semver.parse(tag).patch}`;
5460

55-
const tags = Array.from(tagsSet);
61+
tagsSet.add(minorVersion);
62+
63+
if (minorsToPatches.has(minorVersion)) {
64+
const uniquePatches = Array.from(new Set(minorsToPatches.get(minorVersion)).add(patchVersion));
5665

57-
versions = tags.slice(0, tags.indexOf(MIN_DOCS_VERSION) + 1);
66+
minorsToPatches.set(minorVersion, uniquePatches);
67+
68+
} else {
69+
minorsToPatches.set(minorVersion, [patchVersion]);
70+
}
71+
});
72+
73+
const tags = Array.from(tagsSet);
74+
const versions = tags.slice(0, tags.indexOf(MIN_DOCS_VERSION) + 1);
75+
// Converting the map, as it's later changed to JSON.
76+
const versionsWithPatches = Array.from(minorsToPatches).slice(0, MAX_MINORS_COUNT);
5877

5978
logger.info(`Fetched the following Docs versions: ${versions.join(', ')}`);
6079
logger.info(`GitHub API rate limits:
@@ -64,8 +83,9 @@ async function readFromGitHub() {
6483
`);
6584

6685
return {
67-
versions,
86+
versions, // Please keep in mind that we have more version than displayed for purpose of creating canonicals.
6887
latestVersion: versions[0],
88+
versionsWithPatches,
6989
};
7090
}
7191

@@ -93,6 +113,7 @@ async function fetchDocsVersions() {
93113

94114
if (process.env.BUILD_MODE !== 'production') {
95115
docsData.versions = ['next', ...docsData.versions];
116+
docsData.versionsWithPatches = [['next', []], ...docsData.versionsWithPatches];
96117
docsData.latestVersion = 'next';
97118
}
98119

docs/.vuepress/plugins/dump-docs-data/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const docsDataCommon = {
1616
versions: [],
1717
latestVersion: '',
1818
urls: [],
19+
versionsWithPatches: [],
1920
};
2021

2122
module.exports = (options, context) => {
@@ -53,6 +54,7 @@ module.exports = (options, context) => {
5354
docsDataCommon.urls = Array.from(canonicalURLs);
5455
docsDataCommon.versions = docsVersions.versions;
5556
docsDataCommon.latestVersion = docsVersions.latestVersion;
57+
docsDataCommon.versionsWithPatches = docsVersions.versionsWithPatches;
5658

5759
try {
5860
await fsp.writeFile(`${outputDir}/common.json`, JSON.stringify(docsDataCommon));

docs/.vuepress/theme/components/DropdownLink.vue

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,21 @@
6161
</li>
6262
</ul>
6363

64-
<NavLink
65-
v-else
66-
:item="subItem"
67-
@click.native="itemClick(subItem)"
68-
@focusout="isLastItemOfArray(subItem, item.items) && setOpen(false)"
69-
/>
64+
<a
65+
class="nav-link"
66+
:href="subItem.link"
67+
>
68+
<ul
69+
class="dropdown-subitem-wrapper font-normal"
70+
>
71+
<li class="dropdown-subitem">{{ subItem.text }}</li>
72+
<li v-for="childSubItem in subItem.subitems"
73+
class="dropdown-subitem intend"
74+
>
75+
{{ childSubItem}}
76+
</li>
77+
</ul>
78+
</a>
7079
</li>
7180
</ul>
7281
</DropdownTransition>
@@ -178,8 +187,14 @@ export default {
178187
.dropdown-subitem-wrapper
179188
padding 0
180189
list-style none
190+
&.font-normal .dropdown-subitem
191+
font-size: inherit;
181192
.dropdown-subitem
182193
font-size 0.9em
194+
&.intend
195+
position: relative;
196+
left: 1.5rem;
197+
opacity: .6
183198
a
184199
display block
185200
line-height 1.7rem

docs/.vuepress/theme/components/VersionsDropdown.vue

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@ export default {
2020
};
2121
},
2222
methods: {
23-
addLatest(version) {
24-
if (version === this.$page.latestVersion) {
25-
return `${version} (Current)`;
23+
addLatest(version, showPatch) {
24+
const latestMinor = this.$page.latestVersion;
25+
26+
if (version === latestMinor) {
27+
const patches = this.$page.versionsWithPatches.get(latestMinor);
28+
29+
// It will show patches only when we have at least two versions for certain minor.
30+
if (showPatch === true && patches?.length > 1) {
31+
version = patches[0];
32+
}
33+
34+
return `${version} (Latest)`;
2635
}
2736
2837
return version;
@@ -34,43 +43,19 @@ export default {
3443
3544
return `/docs/${version}/`;
3645
},
37-
getLegacyVersions() {
38-
return [
39-
'8.4.0',
40-
'8.3.2',
41-
'8.2.0',
42-
'8.1.0',
43-
'8.0.0',
44-
'7.4.2',
45-
'7.3.0',
46-
'7.2.2',
47-
'7.1.1',
48-
'7.0.3',
49-
'6.2.2',
50-
'6.1.1',
51-
'6.0.1',
52-
'5.0.2',
53-
'4.0.0',
54-
].map(version => ({
55-
text: version.replace(/\.\d+$/, ''),
56-
link: `/docs/${version}/`,
57-
target: '_blank',
58-
isHtmlLink: true,
59-
}));
60-
}
6146
},
6247
mounted() {
6348
this.item = {
64-
text: this.addLatest(this.$page.currentVersion),
49+
text: this.addLatest(this.$page.currentVersion, true),
6550
items:
6651
[
67-
...this.$page.versions.map(v => ({
68-
text: `${this.addLatest(v)}`,
52+
...Array.from(this.$page.versionsWithPatches.keys()).map(v => ({
53+
text: `${this.addLatest(v, false)}`,
6954
link: this.getLink(v),
7055
target: '_self',
71-
isHtmlLink: true
56+
isHtmlLink: true,
57+
subitems: this.$page.versionsWithPatches.get(v),
7258
})),
73-
...this.getLegacyVersions()
7459
]
7560
};
7661
}

docs/.vuepress/theme/styles/theme-dark.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ html.theme-dark {
106106
background-color $backgroundColor
107107
border-color $sectionBorderColor
108108

109-
.dropdown-item a:hover {
109+
.dropdown-item:hover {
110110
background: #2b2f33;
111111
}
112112
}

0 commit comments

Comments
 (0)