Skip to content

Commit

Permalink
feat: allow use other name to replace origin version (apache#1349)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyeYoung authored Sep 28, 2022
1 parent 824e93a commit 4db177c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 10 additions & 1 deletion config/apisix-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ const versions = ['2.12', '2.13', '2.14', '2.15', '2.99'];
*/
const LTSVersions = ['2.15'];

/**
* @type {{[origin: string]: string}} version display name mapping to origin name
*/
const versionMap = {
'2.99': '3.0.0-beta',
};

/**
* @type {Array<{label: string, href: string}>}
*/
Expand Down Expand Up @@ -48,4 +55,6 @@ const archivedVersions = [
},
];

module.exports = { versions, LTSVersions, archivedVersions };
module.exports = {
versions, LTSVersions, versionMap, archivedVersions,
};
11 changes: 6 additions & 5 deletions scripts/sync-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const semver = require('semver');
const replace = require('replace-in-file');

const common = require('./common.js');
const { versions } = require('../config/apisix-versions.js');
const { versions, versionMap } = require('../config/apisix-versions.js');

const { projects, languages, projectPaths } = common;
const tempPath = './temp';
Expand Down Expand Up @@ -94,7 +94,7 @@ const tasks = new Listr([
if (versions.length === 0) return Promise.resolve();

if (await isFileExisted(target)) await fs.rm(target);
return fs.writeFile(target, JSON.stringify(versions.reverse(), null, 2));
return fs.writeFile(target, JSON.stringify(versions.map((v) => versionMap[v] || v).reverse(), null, 2));
};

const extractTasks = projectPaths.map((project) => ({
Expand Down Expand Up @@ -354,16 +354,17 @@ function extractDocsVersionTasks(project, version) {
const docsPath = `${projectPath}/docs`;
const enSrcDocs = `${docsPath}/en/latest`;
const zhSrcDocs = `${docsPath}/zh/latest`;
const enTargetDocs = `${websitePath}/docs-${projectName}_versioned_docs/version-${version}`;
const zhTargetDocs = `${websitePath}/i18n/zh/docusaurus-plugin-content-docs-docs-${projectName}/version-${version}`;
const displayVersionName = (projectName === 'apisix' && versionMap?.[version]) || version;
const enTargetDocs = `${websitePath}/docs-${projectName}_versioned_docs/version-${displayVersionName}`;
const zhTargetDocs = `${websitePath}/i18n/zh/docusaurus-plugin-content-docs-docs-${projectName}/version-${displayVersionName}`;

await Promise.allSettled([
copyDocs(enSrcDocs, enTargetDocs)
.then(() => replaceMDElements(projectName, [enTargetDocs], branchName))
.then(() => handleConfig2Sidebar(
enTargetDocs,
enTargetDocs,
version,
displayVersionName,
`${websitePath}/docs-${project.name}_versioned_sidebars`,
)),
copyDocs(zhSrcDocs, zhTargetDocs).then(() => replaceMDElements(projectName, [zhTargetDocs], branchName)),
Expand Down

0 comments on commit 4db177c

Please sign in to comment.