Skip to content

Commit 8df1625

Browse files
authored
Merge pull request #170 from apache/fix-version-replace
fix version replace
2 parents 8d9f405 + f3b1038 commit 8df1625

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

site2/website-next/scripts/replace.js

+35-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const CWD = process.cwd();
66
const siteConfig = require(`${CWD}/docusaurus.config.js`);
77
const nextDocsDir = `${CWD}/docs`;
88
const docsDir = `${CWD}/versioned_docs`;
9+
const restApiVersions = require("../static/swagger/restApiVersions.json");
10+
const compareVersions = require("compare-versions");
911

1012
function getVersions() {
1113
try {
@@ -19,6 +21,28 @@ function getVersions() {
1921
return ["2.1.0"];
2022
}
2123

24+
function getRealVersion(version) {
25+
let versionMap = {};
26+
let _vsGroups = {};
27+
for (let [key, val] of Object.entries(restApiVersions)) {
28+
if (key == "master" || compareVersions.compare(key, "2.8.0", "<")) {
29+
versionMap[key] = key;
30+
} else {
31+
let [one, two] = key.split(".");
32+
let _tKey = one + "." + two + ".x";
33+
_vsGroups[_tKey] = [...(_vsGroups[_tKey] || []), key];
34+
}
35+
}
36+
for (let [key, val] of Object.entries(_vsGroups)) {
37+
let _tKey = val.sort((a, b) => {
38+
return -compareVersions.compare(b, a, "<");
39+
})[0];
40+
versionMap[key] = _tKey;
41+
}
42+
console.log("..., ", versionMap);
43+
return versionMap[version];
44+
}
45+
2246
function downloadPageUrl() {
2347
return `${siteConfig.baseUrl}download`;
2448
}
@@ -91,13 +115,16 @@ function debDistUrl(version, type) {
91115
}
92116

93117
function clientVersionUrl(version, type) {
94-
var versions = version.split('.')
95-
var majorVersion = parseInt(versions[0])
96-
var minorVersion = parseInt(versions[1])
97-
if ((majorVersion === 2 && minorVersion < 5) || (type === "python" && minorVersion >= 7)) {
118+
var versions = version.split(".");
119+
var majorVersion = parseInt(versions[0]);
120+
var minorVersion = parseInt(versions[1]);
121+
if (
122+
(majorVersion === 2 && minorVersion < 5) ||
123+
(type === "python" && minorVersion >= 7)
124+
) {
98125
return `(${siteConfig.url}/api/${type}/${version}`;
99126
} else if (majorVersion >= 2 && minorVersion >= 5) {
100-
return `(${siteConfig.url}/api/${type}/${majorVersion}.${minorVersion}.0-SNAPSHOT`
127+
return `(${siteConfig.url}/api/${type}/${majorVersion}.${minorVersion}.0-SNAPSHOT`;
101128
}
102129
}
103130

@@ -190,10 +217,11 @@ doReplace(options);
190217

191218
// TODO activate and test when first version of docs are cut
192219
// replaces versions
193-
for (v of versions) {
220+
for (_v of versions) {
194221
// if (v === latestVersion) {
195222
// continue;
196223
// }
224+
const v = getRealVersion(_v)
197225
const vWithoutIncubating = v.replace("-incubating", "");
198226
const opts = {
199227
files: [
@@ -232,4 +260,4 @@ for (v of versions) {
232260
dry: false,
233261
};
234262
doReplace(opts);
235-
}
263+
}

site2/website-next/src/utils/index.js

-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export function getApiVersion(anchor) {
6565
let apiVersion = "";
6666
let _restApiVs = {};
6767
let _vsGroups = {};
68-
console.log('...1, ', restApiVersions)
6968
for (let [key, val] of Object.entries(restApiVersions)) {
7069
if (key == 'master' || compareVersions.compare(key, "2.8.0", "<")) {
7170
_restApiVs[key] = val;
@@ -75,21 +74,18 @@ export function getApiVersion(anchor) {
7574
_vsGroups[_tKey] = [...(_vsGroups[_tKey] || []), key];
7675
}
7776
}
78-
console.log('...2, ', _vsGroups)
7977
for (let [key, val] of Object.entries(_vsGroups)) {
8078
let _tKey = val.sort((a, b) => {
8179
return -compareVersions.compare(b, a, "<");
8280
})[0];
8381
_restApiVs[key] = restApiVersions[_tKey];
8482
}
85-
console.log('...3, ', _restApiVs)
8683

8784
if (_restApiVs[version][0]["fileName"].indexOf(anchor) == 0) {
8885
apiVersion = _restApiVs[version][0]["version"];
8986
} else {
9087
apiVersion = _restApiVs[version][1]["version"];
9188
}
92-
console.log('...4', apiVersion)
9389

9490
return apiVersion;
9591
}

0 commit comments

Comments
 (0)