This is an automated email from the ASF dual-hosted git repository. liuxiran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix-website.git
The following commit(s) were added to refs/heads/master by this push: new 20a2671 feat: support custom branch (#377) 20a2671 is described below commit 20a2671fd3aa494449604905e5f920a1f676e5ec Author: ηθ΄θΏ <juzhiy...@apache.org> AuthorDate: Thu Jun 24 09:19:36 2021 +0800 feat: support custom branch (#377) --- common.js | 36 +++++++++++++++++++++++++++++------- sync-docs.js | 45 ++++++++++++++++----------------------------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/common.js b/common.js index 57aeba6..4d91bd2 100644 --- a/common.js +++ b/common.js @@ -1,16 +1,38 @@ -const projects = ["apisix-ingress-controller", "apisix", "apisix-dashboard", "apisix-docker", "apisix-helm-chart", "apisix-java-plugin-runner"]; +const projects = [ + { + name: "apisix-ingress-controller", + branch: "master" + }, { + name: "apisix", + branch: "master" + }, { + name: "apisix-dashboard", + branch: "master" + }, { + name: "apisix-docker", + branch: "master" + }, { + name: "apisix-helm-chart", + branch: "master" + }, { + name: "apisix-java-plugin-runner", + branch: "main" + } +]; + const languages = ["en", "zh", "es"]; module.exports = { projects, languages, - projectPaths: () => projects.map((project) => { + projectPaths: projects.map((project) => { return { - project: project, - pluginId: `docs-${project}`, - paths: { - en: `./website/docs/${project}`, - zh: `./website/i18n/zh/docusaurus-plugin-content-docs-docs-${project}/current`, + name: project.name, + pluginId: `docs-${project.name}`, + branch: project.branch, + latestDocs: { + en: `./website/docs/${project.name}`, + zh: `./website/i18n/zh/docusaurus-plugin-content-docs-docs-${project.name}/current`, }, }; }) diff --git a/sync-docs.js b/sync-docs.js index c457d4a..b52bf8d 100644 --- a/sync-docs.js +++ b/sync-docs.js @@ -9,25 +9,13 @@ const fs = require("fs"); const path = require("path"); const common = require("./common.js"); -const projects = common.projects; -const langs = common.languages; - -const projectPaths = projects.map((project) => { - return { - project: project, - pluginId: `docs-${project}`, - latestDocs: { - en: `./website/docs/${project}`, - zh: `./website/i18n/zh/docusaurus-plugin-content-docs-docs-${project}/current`, - }, - }; -}); +const { projects, languages, projectPaths } = common; const isFileExisted = (path) => { return fs.existsSync(path); }; -const replaceMDElements = (project, path) => { +const replaceMDElements = (project, path, branch = "master") => { const replace = require("replace-in-file"); const allMDFilePaths = path.map((p) => `${p}/**/*.md`); @@ -38,7 +26,7 @@ const replaceMDElements = (project, path) => { from: /(\.\.\/)+assets\/images\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g, to: (match) => { const imgPath = match.replace(/\(|\)|\.\.\/*/g, ""); - const newUrl = `https://raw.githubusercontent.com/apache/${project}/master/docs/${imgPath}`; + const newUrl = `https://raw.githubusercontent.com/apache/${project}/${branch}/docs/${imgPath}`; console.log(`${project}: ${match} π ${newUrl}`); return newUrl; }, @@ -48,22 +36,21 @@ const replaceMDElements = (project, path) => { const markdownOptions = { files: allMDFilePaths, from: RegExp( - `\\[.*\\]\\((\\.\\.\\/)*(${langs.join("|")})\\/.*\\.md\\)`, + `\\[.*\\]\\((\\.\\.\\/)*(${languages.join("|")})\\/.*\\.md\\)`, "g" ), to: (match) => { const markdownPath = match.replace(/\(|\)|\.\.\/*|\[.*\]|\.\//g, ""); // "en/latest/discovery/dns.md" const lang = markdownPath.split("/")[0]; const urlPath = markdownPath.replace( - RegExp(`(${langs.join("|")})\\/latest\\/|\\.md`, "g"), + RegExp(`(${languages.join("|")})\\/latest\\/|\\.md`, "g"), "" ); // "discovery/dns" const projectNameWithoutPrefix = project === "apisix" ? "apisix" : project.replace("apisix-", ""); let newUrl = match.replace( /\]\(.*\)/g, - `](https://apisix.apache.org${ - lang !== "en" ? "/" + lang : "" + `](https://apisix.apache.org${lang !== "en" ? "/" + lang : "" }/docs/${projectNameWithoutPrefix}/${urlPath})` ); log(`${project}: ${match} π ${newUrl}`); @@ -143,15 +130,15 @@ const copyDocs = (source, target, projectName, locale) => { const copyAllDocs = (project) => { copyDocs( - `./tmp/${project.project}/docs`, + `./tmp/${project.name}/docs`, project.latestDocs.en, - project.project, + project.name, "en" ); copyDocs( - `./tmp/${project.project}/docs`, + `./tmp/${project.name}/docs`, project.latestDocs.zh, - project.project, + project.name, "zh" ); }; @@ -159,7 +146,7 @@ const copyAllDocs = (project) => { const cloneRepos = () => { log("Clone repos"); const gitCommand = projects - .map((project) => `git clone https://github.com/apache/${project}.git`) + .map((project) => `git clone https://github.com/apache/${project.name}.git`) .join(" & "); childProcess.execSync(gitCommand, { cwd: "./tmp" }); }; @@ -211,7 +198,7 @@ const main = () => { log("Versioning"); projectPaths.map((project) => { - const projectName = project.project; + const projectName = project.name; const versions = findReleaseVersions(projectName); versions.map((version) => { log(`Versioning for ${project} version: ${version}`); @@ -220,7 +207,7 @@ const main = () => { }); log("Replace elements inside MD files"); - replaceMDElements(projectName, [`./tmp/${projectName}/docs`]); + replaceMDElements(projectName, [`./tmp/${projectName}/docs`], project.branch); copyAllDocs(project); // versioning English docs @@ -240,13 +227,13 @@ const main = () => { log("Copy next version docs"); projectPaths.map((project) => { - const projectName = project.project; - childProcess.execSync(`git checkout -f master`, { + const projectName = project.name; + childProcess.execSync(`git checkout -f ${project.branch}`, { cwd: `./tmp/${projectName}`, }); log("Replace elements inside MD files"); - replaceMDElements(projectName, [`./tmp/${projectName}/docs`]); + replaceMDElements(projectName, [`./tmp/${projectName}/docs`], project.branch); copyAllDocs(project); });