This is an automated email from the ASF dual-hosted git repository. urfree pushed a commit to branch fix-version-replace in repository https://gitbox.apache.org/repos/asf/pulsar-site.git
commit f3b1038d4f3b17cda33c3363c81a48a168a6f5b0 Author: Li Li <[email protected]> AuthorDate: Mon Aug 22 10:45:00 2022 +0800 fix version replace Signed-off-by: Li Li <[email protected]> --- site2/website-next/scripts/replace.js | 42 +++++++++++++++++++++++++++++------ site2/website-next/src/utils/index.js | 4 ---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/site2/website-next/scripts/replace.js b/site2/website-next/scripts/replace.js index 93b6e7aac3e..53d630c3c91 100644 --- a/site2/website-next/scripts/replace.js +++ b/site2/website-next/scripts/replace.js @@ -6,6 +6,8 @@ const CWD = process.cwd(); const siteConfig = require(`${CWD}/docusaurus.config.js`); const nextDocsDir = `${CWD}/docs`; const docsDir = `${CWD}/versioned_docs`; +const restApiVersions = require("../static/swagger/restApiVersions.json"); +const compareVersions = require("compare-versions"); function getVersions() { try { @@ -19,6 +21,28 @@ function getVersions() { return ["2.1.0"]; } +function getRealVersion(version) { + let versionMap = {}; + let _vsGroups = {}; + for (let [key, val] of Object.entries(restApiVersions)) { + if (key == "master" || compareVersions.compare(key, "2.8.0", "<")) { + versionMap[key] = key; + } else { + let [one, two] = key.split("."); + let _tKey = one + "." + two + ".x"; + _vsGroups[_tKey] = [...(_vsGroups[_tKey] || []), key]; + } + } + for (let [key, val] of Object.entries(_vsGroups)) { + let _tKey = val.sort((a, b) => { + return -compareVersions.compare(b, a, "<"); + })[0]; + versionMap[key] = _tKey; + } + console.log("..., ", versionMap); + return versionMap[version]; +} + function downloadPageUrl() { return `${siteConfig.baseUrl}download`; } @@ -91,13 +115,16 @@ function debDistUrl(version, type) { } function clientVersionUrl(version, type) { - var versions = version.split('.') - var majorVersion = parseInt(versions[0]) - var minorVersion = parseInt(versions[1]) - if ((majorVersion === 2 && minorVersion < 5) || (type === "python" && minorVersion >= 7)) { + var versions = version.split("."); + var majorVersion = parseInt(versions[0]); + var minorVersion = parseInt(versions[1]); + if ( + (majorVersion === 2 && minorVersion < 5) || + (type === "python" && minorVersion >= 7) + ) { return `(${siteConfig.url}/api/${type}/${version}`; } else if (majorVersion >= 2 && minorVersion >= 5) { - return `(${siteConfig.url}/api/${type}/${majorVersion}.${minorVersion}.0-SNAPSHOT` + return `(${siteConfig.url}/api/${type}/${majorVersion}.${minorVersion}.0-SNAPSHOT`; } } @@ -190,10 +217,11 @@ doReplace(options); // TODO activate and test when first version of docs are cut // replaces versions -for (v of versions) { +for (_v of versions) { // if (v === latestVersion) { // continue; // } + const v = getRealVersion(_v) const vWithoutIncubating = v.replace("-incubating", ""); const opts = { files: [ @@ -232,4 +260,4 @@ for (v of versions) { dry: false, }; doReplace(opts); -} +} \ No newline at end of file diff --git a/site2/website-next/src/utils/index.js b/site2/website-next/src/utils/index.js index 080acc05d0c..4ef5b937d03 100644 --- a/site2/website-next/src/utils/index.js +++ b/site2/website-next/src/utils/index.js @@ -65,7 +65,6 @@ export function getApiVersion(anchor) { let apiVersion = ""; let _restApiVs = {}; let _vsGroups = {}; - console.log('...1, ', restApiVersions) for (let [key, val] of Object.entries(restApiVersions)) { if (key == 'master' || compareVersions.compare(key, "2.8.0", "<")) { _restApiVs[key] = val; @@ -75,21 +74,18 @@ export function getApiVersion(anchor) { _vsGroups[_tKey] = [...(_vsGroups[_tKey] || []), key]; } } - console.log('...2, ', _vsGroups) for (let [key, val] of Object.entries(_vsGroups)) { let _tKey = val.sort((a, b) => { return -compareVersions.compare(b, a, "<"); })[0]; _restApiVs[key] = restApiVersions[_tKey]; } - console.log('...3, ', _restApiVs) if (_restApiVs[version][0]["fileName"].indexOf(anchor) == 0) { apiVersion = _restApiVs[version][0]["version"]; } else { apiVersion = _restApiVs[version][1]["version"]; } - console.log('...4', apiVersion) return apiVersion; }
