This is an automated email from the ASF dual-hosted git repository.

urfree pushed a commit to branch refactor/migrate-scripts
in repository https://gitbox.apache.org/repos/asf/pulsar-site.git


The following commit(s) were added to refs/heads/refactor/migrate-scripts by 
this push:
     new e9e9635  update
e9e9635 is described below

commit e9e9635fc6e2e75e6038a7c7e0ae08b98bf1262d
Author: LiLi <[email protected]>
AuthorDate: Fri Feb 11 16:57:29 2022 +0800

    update
    
    Signed-off-by: LiLi <[email protected]>
---
 site2/website-next/migration-scripts/.gitignore    |   2 -
 site2/website-next/migration-scripts/auto.js       |  98 ------------
 site2/website-next/migration-scripts/fix-code.js   |  41 -----
 site2/website-next/migration-scripts/fix-jsx.js    |   7 -
 site2/website-next/migration-scripts/fix-kop.js    |  44 -----
 site2/website-next/migration-scripts/fix-md.js     |  54 -------
 site2/website-next/migration-scripts/fix-miss.js   |  59 -------
 site2/website-next/migration-scripts/fix-space.js  |  54 -------
 site2/website-next/migration-scripts/fix-tab.js    |  97 -----------
 site2/website-next/migration-scripts/fix-table.js  |  72 ---------
 .../migration-scripts/fix-tip-note-in-list.js      |  27 ----
 .../website-next/migration-scripts/fix-tip-note.js |  81 ----------
 .../migration-scripts/migrate-chapter.js           | 178 ---------------------
 site2/website-next/migration-scripts/migrate-md.js |  45 ------
 .../migration-scripts/migrate-missing.js           |   3 -
 .../migration-scripts/migrate-override.js          |   3 -
 site2/website-next/migration-scripts/migration.js  |   8 -
 site2/website-next/migration-scripts/migration.sh  |   5 -
 site2/website-next/migration-scripts/override.js   |  44 -----
 19 files changed, 922 deletions(-)

diff --git a/site2/website-next/migration-scripts/.gitignore 
b/site2/website-next/migration-scripts/.gitignore
deleted file mode 100644
index 89db65e..0000000
--- a/site2/website-next/migration-scripts/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-.cache
-/node_modules
\ No newline at end of file
diff --git a/site2/website-next/migration-scripts/auto.js 
b/site2/website-next/migration-scripts/auto.js
deleted file mode 100644
index 84bce81..0000000
--- a/site2/website-next/migration-scripts/auto.js
+++ /dev/null
@@ -1,98 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-const lodash = require("lodash");
-const child_process = require("child_process");
-const migrate = require("./migrate-chapter");
-const override = require("./override");
-
-const args = process.argv.slice(2);
-const version = args[0];
-let rerun = version == "rerun";
-
-function run(rerun) {
-  if (rerun) {
-    let cache = fs.readFileSync(path.join(__dirname, ".cache"), "utf8");
-    cache = JSON.parse(cache);
-    console.log(
-      "auto migrate docs for version: ",
-      cache.version,
-      "chapter: ",
-      cache.chapter
-    );
-    migrate(cache.version, cache.chapter, "");
-    return;
-  }
-
-  let version_full = "version-" + version;
-  let src = "../../website/versioned_docs/" + version_full;
-  let dest = "../../website-next/versioned_docs/" + version_full;
-  if (version == "next") {
-    src = "../../docs";
-    dest = "../../website-next/docs";
-  }
-  src = path.join(__dirname, src);
-  dest = path.join(__dirname, dest);
-
-  let sidebar_file = path.join(
-    __dirname,
-    "../../website/versioned_sidebars/" + version_full + "-sidebars.json"
-  );
-  if (version == "next") {
-    sidebar_file = path.join(__dirname, "../../website/sidebars.json");
-  }
-  let sidebar = fs.readFileSync(sidebar_file, "utf8");
-  sidebar = JSON.parse(sidebar);
-
-  sidebar = sidebar[version == "next" ? "docs" : version_full + "-docs"];
-
-  let new_sidebar_file = path.join(
-    __dirname,
-    "../../website-next/versioned_sidebars/" + version_full + "-sidebars.json"
-  );
-  if (version == "next") {
-    new_sidebar_file = path.join(__dirname, 
"../../website-next/sidebars.json");
-  }
-
-  let chapters = Object.keys(sidebar);
-
-  function migrateChapter() {
-    let new_sidebar = [];
-    let new_sidebar_map = {};
-    if (fs.existsSync(new_sidebar_file)) {
-      new_sidebar = JSON.parse(fs.readFileSync(new_sidebar_file, "utf8"));
-      let key =
-        version == "next" ? "docsSidebar" : version_full + "/docsSidebar";
-      new_sidebar = new_sidebar[key];
-      new_sidebar_map = lodash.keyBy(new_sidebar, "label");
-    }
-
-    let migrated_chapters = Object.keys(new_sidebar_map);
-
-    let need_migration_chapers = lodash.difference(chapters, 
migrated_chapters);
-
-    let current_chapter =
-      need_migration_chapers.length > 0 ? need_migration_chapers[0] : null;
-    if (current_chapter) {
-      console.log(
-        "auto migrate docs for version: ",
-        version,
-        "chapter: ",
-        current_chapter
-      );
-      migrate(version, current_chapter, "");
-      fs.writeFileSync(
-        path.join(__dirname, ".cache"),
-        JSON.stringify({ version: version, chapter: current_chapter })
-      );
-    } else {
-      console.log(
-        "所有章节已迁移完成,现在执行一次完整的【" + version + "】copy fix"
-      );
-      override(version);
-    }
-  }
-
-  migrateChapter();
-}
-
-run(rerun);
diff --git a/site2/website-next/migration-scripts/fix-code.js 
b/site2/website-next/migration-scripts/fix-code.js
deleted file mode 100644
index b297473..0000000
--- a/site2/website-next/migration-scripts/fix-code.js
+++ /dev/null
@@ -1,41 +0,0 @@
-module.exports = (data) => {
-  let nData = data;
-
-  let reg = /^([\t ]*)(>*)([\t ]*)(```.*)((((?!```).)*\n*)+)```/gm; //代码块
-  while ((codeGroup = reg.exec(data))) {
-    let _match = codeGroup[0];
-    let space1 = codeGroup[1];
-    let arrow = codeGroup[2];
-    let space2 = codeGroup[3];
-    let begin = codeGroup[4];
-    let code = codeGroup[5];
-    let prefix = space1 + arrow + space2;
-    if ((code = /[\t ]*(.+\n*)*\S/.exec(code))) {
-      code = code[0]; //剔除纯空白的行首和行尾, 得到纯代码
-      if (code.substr(0, prefix.length) != prefix) {
-        code = prefix + code.replace(/\n(.*)/g, "\n" + prefix + "$1"); //行对齐
-      }
-    }
-    let newCodeBlock =
-      "\n" +
-      prefix +
-      begin +
-      "\n" +
-      prefix +
-      "\n" +
-      code +
-      "\n" +
-      prefix +
-      "\n" +
-      prefix +
-      "```" +
-      "\n";
-    nData = nData.replace(_match, newCodeBlock);
-  }
-  return nData
-    .replace(
-      /(.*)(\s*\n){3,}(\s*```.*)((((?!```).)*\n*)+)```.*(\s*\n)+/g,
-      "$1\n\n$3$4```\n\n"
-    ) //解决多个空行
-    .replace(/^(\s*```.*(((?!```).)*\n*)+)```.*\n+/gm, "$1```\n\n"); //解决多个空行 
//解决代码块结束标识符后无空行
-};
diff --git a/site2/website-next/migration-scripts/fix-jsx.js 
b/site2/website-next/migration-scripts/fix-jsx.js
deleted file mode 100644
index 48bce1c..0000000
--- a/site2/website-next/migration-scripts/fix-jsx.js
+++ /dev/null
@@ -1,7 +0,0 @@
-module.exports = (data) => {
-  return data
-    .replace(/(import Tabs from '@theme\/Tabs';)/g, "````mdx-code-block\n$1")
-    .replace(/(import TabItem from '@theme\/TabItem';)/g, "$1\n````")
-    .replace(/(<Tabs>?)/g, "````mdx-code-block\n$1")
-    .replace(/(<\/Tabs>)/g, "$1\n````");
-};
diff --git a/site2/website-next/migration-scripts/fix-kop.js 
b/site2/website-next/migration-scripts/fix-kop.js
deleted file mode 100644
index cad71c1..0000000
--- a/site2/website-next/migration-scripts/fix-kop.js
+++ /dev/null
@@ -1,44 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-const axios = require("axios");
-
-const versionReg = /^v(\d+\.?){3,4}$/gm;
-const dir = "/Users/leo/space/sn/pulsar-hub/protocol-handlers/kop";
-const tags_url =
-  
"https://urfreespace:[email protected]/repos/streamnative/kop/tags";;
-const kop_md_url =
-  
"https://urfreespace:ghp_yramcnmbemdopczt1v9pdwv5psjz4n3m1...@raw.githubusercontent.com/streamnative/kop/{{version}}/docs/kop.md";;
-
-async function fix() {
-  let { data } = await axios({
-    method: "get",
-    url: tags_url,
-    proxy: {
-      host: "127.0.0.1",
-      port: 7890,
-    },
-  });
-  let tags = data
-    .map((item) => item.name)
-    .filter((item) => versionReg.test(item));
-  // console.log(tags);
-  for (let tag of tags) {
-    let url = kop_md_url.replace(/{{version}}/, tag);
-    let { data } = await axios({
-      method: "get",
-      url: url,
-      proxy: {
-        host: "127.0.0.1",
-        port: 7890,
-      },
-    });
-    let _path = path.join(dir, tag.substr(1));
-    if (!fs.existsSync(_path)) {
-      fs.mkdirSync(_path);
-    }
-    data = data.replace(/kop\/blob\/master/g, "kop/blob/" + tag);
-    fs.writeFileSync(path.join(_path, "kop.md"), data);
-  }
-}
-
-fix();
diff --git a/site2/website-next/migration-scripts/fix-md.js 
b/site2/website-next/migration-scripts/fix-md.js
deleted file mode 100644
index 14f15bc..0000000
--- a/site2/website-next/migration-scripts/fix-md.js
+++ /dev/null
@@ -1,54 +0,0 @@
-const fixTab = require("./fix-tab");
-const fixTipNote = require("./fix-tip-note");
-const fixTable = require("./fix-table");
-const fixCode = require("./fix-code");
-const fixTipNoteInList = require("./fix-tip-note-in-list");
-const fixJSX = require("./fix-jsx");
-
-function fix(data, version) {
-  let reg = new RegExp("id:\\s*version-" + version + "-(incubating-)?");
-  data = fixTable(data);
-  data = fixTab(data);
-  data = data.replace(/(<TabItem.*)\n(.*{@inject:\s*.+?})/g, "$1\n\n$2");
-  data = data.replace(/^(>\s*```\w*)(\s*\n){2,}>/gm, "$1\n>\n>");
-  data = fixTipNote(data);
-  data = fixTipNoteInList(data);
-  data = fixCode(data);
-
-  data = data
-    .replace(reg, "id: ")
-    .replace("id: deploy-docs", "id: deploy-dcos")
-    .replace(/`{4,}/g, "```")
-    .replace(/^(id:\sstandalone)\s*$/gm, "slug: /\n$1")
-    .replace(/<style[\s\S]*?<\/style>/g, "")
-    .replace(/\[(.*)\]\s*\((.*)\.md\)/g, "[$1]($2)")
-    .replace(/\*\*(((?!\*).)+)\*/g, "**$1**") //**macOS* => **macOS**
-    .replace(/\*\*(((?!\*).)+)\*{3}/g, "**$1**") //**macOS*** => **macOS**
-    .replace(/(\w)[\t ]*\n\[/g, "$1 [")
-    .replace(/sidebar_label:\s*(.*)/, 'sidebar_label: "$1"')
-    .replace(/""(.*)""/, '"$1"')
-    .replace(/\[\[pulsar:version_number\]\]/g, "@pulsar:version_number@")
-    .replace(/{{(pulsar:.*?)}}/g, "@$1@")
-    .replace(/(@inject:\s*\w+:)`(\w+)`/g, "$1$2")
-    .replace(/<empty string>/g, "|")
-    .replace(/<li>(((?!<\/?li>|\|).)+)/g, "<li>$1</li>")
-    .replace(/<\/li>\s*<\/li>/g, "</li>")
-    .replace(/\|(((?!<\/?li>|\|).)+)<\/li>/g, "|<li>$1</li>")
-    .replace(/<\/li>\s*<\/li>/g, "</li>") //sometimes needed, no idea for 
now...
-    .replace(/<\/br>/g, "@AAA@")
-    .replace(/<br>/g, "@AAA@")
-    .replace(/<br\/>/g, "@AAA@")
-    .replace(/<>/g, "")
-    .replace(/@AAA@/g, "<br />")
-    .replace(
-      /<span style="(((?!:).)+):(((?!>).)+);"/g,
-      '<span style={{color: "$3"}}'
-    )
-    .replace(/\s?style=".*?"/g, "")
-    .replace(/\]\(assets\//g, "](/assets/");
-
-  return data;
-  // return fixJSX(data);
-}
-
-module.exports = fix;
diff --git a/site2/website-next/migration-scripts/fix-miss.js 
b/site2/website-next/migration-scripts/fix-miss.js
deleted file mode 100644
index f20574b..0000000
--- a/site2/website-next/migration-scripts/fix-miss.js
+++ /dev/null
@@ -1,59 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-
-function fix(docId, versions) {
-  console.log("Fix missing for: ", docId, versions);
-
-  let fixed = false;
-
-  function travel(dir, callback) {
-    fs.readdirSync(dir)
-      .sort(() => -1)
-      .forEach((file) => {
-        var pathname = path.join(dir, file);
-        if (fs.statSync(pathname).isDirectory()) {
-          if (!fixed) {
-            travel(pathname, callback);
-          }
-        } else {
-          if (!fixed) {
-            fixed = callback(pathname);
-          }
-        }
-      });
-  }
-
-  const vdocs = path.join(__dirname, "../../website/versioned_docs");
-  travel(vdocs, (pathname) => {
-    let data = fs.readFileSync(pathname, "utf8");
-    let _match = /^id:\s*version-[\d\.]+-(incubating-)?(.*)/gm.exec(data);
-    //   if (_match[1].indexOf(docId) > -1) {
-    if (_match && _match[2] == docId) {
-      console.log(pathname, _match[0]);
-
-      let vs = versions.split(",");
-      vs.forEach((v) => {
-        if (v == "next") {
-          fs.writeFileSync(
-            path.join(vdocs, "../../docs/", docId + ".md"),
-            data.replace(/^id:\s*version-[\d\.]+-(.*)/gm, "id: " + docId),
-            "utf8"
-          );
-        } else {
-          fs.writeFileSync(
-            path.join(vdocs, "version-" + v, docId + ".md"),
-            data.replace(
-              /^id:\s*version-[\d\.]+-(.*)/gm,
-              "id: version-" + v + "-" + docId
-            ),
-            "utf8"
-          );
-        }
-      });
-      return true;
-    }
-    return false;
-  });
-}
-
-module.exports = fix;
diff --git a/site2/website-next/migration-scripts/fix-space.js 
b/site2/website-next/migration-scripts/fix-space.js
deleted file mode 100644
index 56dfd99..0000000
--- a/site2/website-next/migration-scripts/fix-space.js
+++ /dev/null
@@ -1,54 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-
-const code_map = {};
-let index = 0;
-
-function fixSpace(data) {
-  const code_reg = /(```\w*)((((?!```).)*\n*)+)```/;
-  const _match = code_reg.exec(data);
-  if (_match) {
-    const code = _match[0];
-    const TMP_KEY = "_TMP_CODE_KEY_" + index + "_";
-    code_map[TMP_KEY] = code;
-    index++;
-    data = data.replace(code_reg, TMP_KEY);
-    return fixSpace(data);
-  } else {
-    return data;
-  }
-}
-
-function fixTmp(data) {
-  const tmp_reg = /_TMP_CODE_KEY_(\d+)_/;
-  const _match = tmp_reg.exec(data);
-  if (_match) {
-    data = data.replace(tmp_reg, code_map[_match[0]]);
-    return fixTmp(data);
-  } else {
-    return data;
-  }
-}
-
-function fix(data) {
-  data = fixSpace(data);
-  data = data.replace(/^[\t ]+/gm, "");
-  data = fixTmp(data);
-  return data;
-}
-
-function test() {
-  let data = fs.readFileSync(
-    path.join(__dirname, "../bak/io-quickstart.md"),
-    "utf8"
-  );
-  data = fixSpace(data);
-  data = data.replace(/^[\t ]+/gm, "");
-  data = fixTmp(data);
-  // console.log(data);
-  fs.writeFileSync(path.join(__dirname, "../bak/io-quickstart-fixed.md"), 
data);
-}
-
-// test();
-
-module.exports = fix;
diff --git a/site2/website-next/migration-scripts/fix-tab.js 
b/site2/website-next/migration-scripts/fix-tab.js
deleted file mode 100644
index 3dd751a..0000000
--- a/site2/website-next/migration-scripts/fix-tab.js
+++ /dev/null
@@ -1,97 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-const lodash = require("lodash");
-const TAB_REG =
-  /([\t 
]*)<!--DOCUSAURUS_CODE_TABS-->(((?!<!--END_DOCUSAURUS_CODE_TABS-->).)*\n*)*<!--END_DOCUSAURUS_CODE_TABS-->/;
-
-function removeTabTag(tab) {
-  return tab
-    .replace(/<!--DOCUSAURUS_CODE_TABS-->/, "")
-    .replace(/<!--END_DOCUSAURUS_CODE_TABS-->/, "");
-}
-
-function findTabItemNameList(tab) {
-  const _match = tab.match(/<!--(.*)-->/g);
-  return _match.map((item) => {
-    return item.replace("<!--", "").replace("-->", "");
-  });
-}
-
-function replaceTabItemTag(tab) {
-  const tab_item_reg = /([\t ]*)<!--(.*)-->((((?![\t ]*<!--).)*\n*)*)/;
-  const _match = tab_item_reg.exec(tab);
-  if (_match) {
-    const space = _match[1];
-    const tab_item_name = _match[2];
-    const tab_item_content = lodash.trimEnd(_match[3]);
-    let tab_item_str = space + '<TabItem value="';
-    tab_item_str +=
-      tab_item_name + '">' + tab_item_content + "\n\n" + space + 
"</TabItem>\n";
-    tab = tab.replace(tab_item_reg, tab_item_str);
-    return replaceTabItemTag(tab);
-  } else {
-    return tab;
-  }
-}
-
-function importTabComponent(data) {
-  if (!/import Tabs from '@theme\/Tabs';/g.exec(data)) {
-    return data.replace(
-      /---((((?!---).)*\n*)*)---/,
-      "---$1---" +
-        "\n\nimport Tabs from '@theme/Tabs';\nimport TabItem from 
'@theme/TabItem';\n"
-    );
-  }
-  return data;
-}
-
-function fixTab(data) {
-  const _match = TAB_REG.exec(data);
-  if (_match) {
-    data = importTabComponent(data);
-    let tab = _match[0];
-    tab = removeTabTag(tab);
-    const names = findTabItemNameList(tab);
-    tab = replaceTabItemTag(tab);
-    const names_map = names.map((item) => {
-      return {
-        label: item,
-        value: item,
-      };
-    });
-
-    const space = _match[1];
-    const tab_tag_begin =
-      space +
-      "<Tabs \n" +
-      space +
-      '  defaultValue="' +
-      names[0] +
-      '"\n' +
-      space +
-      "  values={" +
-      JSON.stringify(names_map) +
-      "}>";
-
-    const tab_tag_end = "\n" + space + "</Tabs>";
-    tab = tab_tag_begin + tab + tab_tag_end;
-    return fixTab(data.replace(TAB_REG, tab));
-  } else {
-    return data
-      .replace(/(<TabItem.*)\n[\t ]*\n/g, "$1\n")
-      .replace(/(<TabItem.*)/g, "$1\n");
-  }
-}
-
-function test() {
-  let data = fs.readFileSync(
-    path.join(__dirname, "../bak/schema-manage.md"),
-    "utf8"
-  );
-  data = fixTab(data);
-  console.log(data);
-}
-
-// test()
-
-module.exports = fixTab;
diff --git a/site2/website-next/migration-scripts/fix-table.js 
b/site2/website-next/migration-scripts/fix-table.js
deleted file mode 100644
index ef629f8..0000000
--- a/site2/website-next/migration-scripts/fix-table.js
+++ /dev/null
@@ -1,72 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-const NL = "\n";
-
-//Convert HTML table to markdown table
-function convertTableElementToMarkdown(table) {
-  let rows = [];
-  let trEls = table.match(/[<]tr[\s\S]*?[/]tr[>]/g);
-  for (let i = 0; i < trEls.length; i++) {
-    let tableRow = trEls[i];
-    let markdownRow = convertTableRowElementToMarkdown(tableRow, i);
-    rows.push(markdownRow);
-  }
-  return rows.join(NL);
-}
-
-//Convert the rows of the HTML table to the rows of the markdown table
-function convertTableRowElementToMarkdown(tableRow, rowNumber) {
-  let cells = [];
-  let cellEls = [];
-  cellEls = tableRow.match(/[<]th[\s\S]*?[/]th[>]/g);
-  if (!cellEls || cellEls.length == 0) {
-    cellEls = tableRow.match(/[<]td[\s\S]*?[/]td[>]/g);
-  }
-  let dividerCells = [];
-  if (rowNumber == 0) {
-    for (i = 0; i < cellEls.length; i++) {
-      dividerCells.push("---" + " |");
-    }
-    dividerCells = "| " + dividerCells.join(" ");
-  }
-  for (let i = 0; i < cellEls.length; i++) {
-    let cell = cellEls[i];
-    cell.indexOf(">") + 1;
-
-    cells.push(
-      cell
-        .substring(cell.indexOf(">") + 1, cell.indexOf("<", cell.indexOf(">")))
-        .replace(/\*\s+([^\|\*]*)/g, "<li>$1</li>") + " | "
-    );
-  }
-  let row = "| " + cells.join(" ");
-  if (rowNumber == 0) {
-    row = row + NL + dividerCells;
-  }
-
-  return row;
-}
-
-function fix(data) {
-  let content = data;
-  let patt1 = /[<]table[\s\S]*?[/]table[>]/g;
-  let tables = content.match(patt1);
-  if (tables) {
-    for (let e of tables) {
-      let et = e.replace(/\s+/g, " ");
-      let markdownTable = convertTableElementToMarkdown(et);
-      content = content.replace(e, markdownTable);
-    }
-  }
-  return content;
-}
-
-function test() {
-  let data = fs.readFileSync(path.join(__dirname, "../bak/txn-how.md"), 
"utf8");
-  data = fix(data);
-  fs.writeFileSync(path.join(__dirname, "../bak/txn-how-fixed.md"), data);
-}
-
-// test();
-
-module.exports = fix;
diff --git a/site2/website-next/migration-scripts/fix-tip-note-in-list.js 
b/site2/website-next/migration-scripts/fix-tip-note-in-list.js
deleted file mode 100644
index 81a3cba..0000000
--- a/site2/website-next/migration-scripts/fix-tip-note-in-list.js
+++ /dev/null
@@ -1,27 +0,0 @@
-module.exports = (data) => {
-  let nData = data;
-  let block = null;
-
-  let uListReg = /^([\*-][\t ]+.*)\n+((\n*[\t ]+.*)*)*/gm;
-
-  while ((block = uListReg.exec(data))) {
-    let content = block[2];
-    if (!content) {
-      continue;
-    }
-    let nContent = content.replace(/^    (?= *)/gm, "  ");
-    nData = nData.replace(content, nContent);
-  }
-
-  let listReg = /^(\d+\.[\t ]+.*)\n+((\n*[\t ]+.*)*)*/gm;
-  while ((block = listReg.exec(data))) {
-    let content = block[2];
-    if (!content) {
-      continue;
-    }
-    let nContent = content.replace(/^    (?= *)/gm, "   ");
-    nData = nData.replace(content, nContent);
-  }
-
-  return nData;
-};
diff --git a/site2/website-next/migration-scripts/fix-tip-note.js 
b/site2/website-next/migration-scripts/fix-tip-note.js
deleted file mode 100644
index 6becf1a..0000000
--- a/site2/website-next/migration-scripts/fix-tip-note.js
+++ /dev/null
@@ -1,81 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-
-function fixTip(data) {
-  const _reg =
-    /^([\t ]*)>[\t ]*#*[\t ]*\**(Note|Tip)+s?:?\**[\t ]*\n(([\t ]*)>[\t 
]*[^><].*\n)+/gm;
-  const _type_reg = /#*[\t ]*\**(Note|Tip)+s?:?\**[\t ]*/i;
-
-  let type = "note";
-  let _tips = data.match(_reg);
-  if (!_tips) {
-    return data;
-  }
-  for (let _tip of _tips) {
-    let tip = _tip.replace(/^[ ]>/gm, ">").replace(/^([\t ]*>)[\t ]*/gm, "$1");
-    let type_match = _type_reg.exec(tip);
-    if (type_match) {
-      type = type_match[1] + "";
-      type = type.toLowerCase();
-    }
-    let space = /^([\t ]*)>/.exec(tip)[1];
-    // if (space.length % 2 == 1) {
-    //   space = space.substr(1);
-    // }
-    tip = tip
-      .replace(_type_reg, "")
-      .replace(/^([\t ]*)>[\t ]*/gm, space)
-      .replace(/^\s*\n/gm, "");
-    tip = space + ":::" + type + "\n\n" + tip + "\n" + space + ":::\n";
-    data = data.replace(_tip, tip);
-  }
-  return data
-    .replace(
-      /(.*)(\s*\n){3,}(\s*:::.*)((((?!:::).)*\n*)+):::.*(\s*\n)+/g,
-      "$1\n\n$3$4:::\n\n"
-    ) //解决多个空行
-    .replace(/(\s*:::.*(((?!:::).)*\n*)+):::.*\n+/g, "$1:::\n\n"); //解决多个空行 
//解决代码块结束标识符后无空行
-}
-
-// function fixListWithTip(data) {
-//   const _reg = /^([*-]\s+.*)([\s\S]*?)(:::[\s\S]*?:::)/gm;
-//   let _match = data.match(_reg);
-//   if (!_match) {
-//     return data;
-//   }
-//   for (let _m of _match) {
-//     let __m = _m.match(/^([*-]\s+.*)([\s\S]*?)(:::[\s\S]*?:::)/m);
-//     let top = __m[1];
-//     let seconds = __m[2];
-//     let tip = __m[3];
-//     // seconds = seconds.replace(/^([\t ]*)(\w+)/gm, "$1* $2");
-//     tip = tip.replace(/^[\t ]+/gm, "");
-//     data = data
-//       .replace(_m, top + seconds + "\n" + tip)
-//       .replace(/(\s*\n){3,}:::/g, "\n\n:::")
-//       .replace(/:::(\s*\n){3,}/g, ":::\n\n");
-//   }
-//   return data;
-// }
-
-function fix(data) {
-  data = fixTip(data);
-  // data = fixListWithTip(data);
-  return data;
-}
-
-function test() {
-  let data = fs.readFileSync(
-    path.join(__dirname, "../bak/tiered-storage-overview.md"),
-    "utf8"
-  );
-  data = fix(data);
-  fs.writeFileSync(
-    path.join(__dirname, "../bak/tiered-storage-overview-fixed.md"),
-    data
-  );
-}
-
-// test();
-
-module.exports = fix;
diff --git a/site2/website-next/migration-scripts/migrate-chapter.js 
b/site2/website-next/migration-scripts/migrate-chapter.js
deleted file mode 100644
index 554f1d5..0000000
--- a/site2/website-next/migration-scripts/migrate-chapter.js
+++ /dev/null
@@ -1,178 +0,0 @@
-//Usage:
-//Example
-//node scripts/migration.js 2.7.3 "Concepts and Architecture" concepts
-//node scripts/migration.js 2.7.3 "Concepts and Architecture" concepts fix
-
-const fs = require("fs");
-const path = require("path");
-const nextSidebar = require("../sidebars");
-const _ = require("lodash");
-const fixMd = require("./fix-md");
-const fixMissing = require("./fix-miss");
-
-function travel(dir, callback) {
-  fs.readdirSync(dir).forEach((file) => {
-    var pathname = path.join(dir, file);
-    if (fs.statSync(pathname).isDirectory()) {
-      // travel(pathname, callback);
-    } else {
-      callback(pathname);
-    }
-  });
-}
-
-module.exports = function migrate(version, category, prefix) {
-  try {
-    console.log(
-      "migration docs for ",
-      "version: ",
-      version,
-      "category: ",
-      category,
-      "prefix: ",
-      prefix
-    );
-
-    let version_full = "version-" + version;
-    let src = "../../website/versioned_docs/" + version_full;
-    let dest = "../../website-next/versioned_docs/" + version_full;
-    if (version == "next") {
-      src = "../../docs";
-      dest = "../../website-next/docs";
-    }
-    src = path.join(__dirname, src);
-    dest = path.join(__dirname, dest);
-
-    let sidebar_file = path.join(
-      __dirname,
-      "../../website/versioned_sidebars/" + version_full + "-sidebars.json"
-    );
-    if (version == "next") {
-      sidebar_file = path.join(__dirname, "../../website/sidebars.json");
-    }
-    let sidebar = fs.readFileSync(sidebar_file, "utf8");
-    sidebar = JSON.parse(sidebar);
-
-    const _key = version == "next" ? "docs" : version_full + "-docs";
-    sidebar = sidebar[_key][category];
-    if (version != "next") {
-      sidebar = sidebar.map((item) => {
-        return item.substr(version_full.length + 1);
-      });
-    }
-    if (!sidebar) {
-      return;
-    }
-    let new_sidebar_file = path.join(
-      __dirname,
-      "../../website-next/versioned_sidebars/" + version_full + 
"-sidebars.json"
-    );
-    let new_sidebar = nextSidebar;
-    if (version == "next") {
-      new_sidebar_file = path.join(
-        __dirname,
-        "../../website-next/sidebars.json"
-      );
-      if (!_.keyBy(new_sidebar.docsSidebar, "label")[category]) {
-        new_sidebar.docsSidebar.push({
-          type: "category",
-          label: category,
-          items: sidebar,
-        });
-      }
-    } else {
-      try {
-        new_sidebar = fs.readFileSync(new_sidebar_file, "utf8");
-        new_sidebar = JSON.parse(new_sidebar);
-      } catch {
-        new_sidebar = {
-          [version_full + "/docsSidebar"]: [],
-        };
-      }
-      if (
-        !_.keyBy(new_sidebar[version_full + "/docsSidebar"], "label")[category]
-      ) {
-        new_sidebar[version_full + "/docsSidebar"].push({
-          type: "category",
-          label: category,
-          items: sidebar.map((item) => {
-            return {
-              type: "doc",
-              id:
-                version_full +
-                "/" +
-                (item == "deploy-docs" ? "deploy-dcos" : item),
-            };
-          }),
-          // collapsible: true,
-          // collapsed: true,
-        });
-      }
-    }
-    fs.writeFileSync(new_sidebar_file, JSON.stringify(new_sidebar, null, 2));
-
-    // console.log("path: ", src, dest);
-    let migrated_docs = [];
-    travel(src, function (pathname) {
-      let filename = path.basename(pathname);
-      try {
-        let stat = fs.statSync(dest);
-        if (!stat.isDirectory()) {
-          fs.mkdirSync(dest);
-        }
-      } catch {
-        fs.mkdirSync(dest);
-      }
-      if (
-        sidebar.includes(filename.substr(0, filename.length - 3)) ||
-        (prefix && filename.startsWith(prefix))
-      ) {
-        console.log(filename);
-        migrated_docs.push(filename.substr(0, filename.length - 3));
-        // if (fix) {
-        let data = fs.readFileSync(pathname, "utf8");
-        data = fixMd(data, version);
-        fs.writeFileSync(
-          path.join(
-            dest,
-            filename
-            // filename == "deploy-dcos.md" ? "deploy-docs.md" : filename
-          ),
-          data
-        );
-        // } else {
-        //   fs.copyFileSync(pathname, path.join(dest, filename));
-        // }
-      } else {
-        let data = fs.readFileSync(pathname, "utf8");
-        let _match = /^id:\s*version-[\d\.]+-(.*)/gm.exec(data);
-        if (_match && sidebar.includes(_match[1])) {
-          // filename = _match[1] + '.md';
-          // if (fix) {
-          console.log(filename);
-          migrated_docs.push(_match[1]);
-          data = fixMd(data, version);
-          fs.writeFileSync(path.join(dest, filename), data);
-          // } else {
-          //   fs.copyFileSync(pathname, path.join(dest, filename));
-          // }
-        }
-      }
-    });
-    let missing_docs = _.difference(sidebar, migrated_docs);
-    if (missing_docs.length > 0) {
-      console.log("fix missing docs:", missing_docs);
-      missing_docs.forEach((docId) => {
-        fixMissing(docId, version);
-        let filename = docId + ".md";
-        let _src = path.join(src, filename);
-        let data = fs.readFileSync(_src, "utf8");
-        data = fixMd(data, version);
-        fs.writeFileSync(path.join(dest, filename), data);
-        fs.unlinkSync(_src);
-      });
-    }
-  } catch (e) {
-    console.error(e);
-  }
-};
diff --git a/site2/website-next/migration-scripts/migrate-md.js 
b/site2/website-next/migration-scripts/migrate-md.js
deleted file mode 100644
index de1d977..0000000
--- a/site2/website-next/migration-scripts/migrate-md.js
+++ /dev/null
@@ -1,45 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-const _ = require("lodash");
-const fixMd = require("./fix-md");
-
-const args = process.argv.slice(2);
-const src = args[0];
-const dest = args[1];
-
-function travel(dir, callback) {
-  fs.readdirSync(dir).forEach((file) => {
-    var pathname = path.join(dir, file);
-    if (fs.statSync(pathname).isDirectory()) {
-      // travel(pathname, callback);
-    } else {
-      callback(pathname);
-    }
-  });
-}
-
-if (!fs.existsSync(src)) {
-  console.log(src, "is not exists.");
-  return;
-}
-
-let stat = fs.statSync(src);
-if (stat.isDirectory()) {
-  stat = fs.statSync(dest);
-  if (!stat.isDirectory()) {
-    fs.mkdirSync(dest);
-  }
-  travel(src, (pathname) => {
-    let data = fs.readFileSync(pathname, "utf8");
-    data = fixMd(data, "blog");
-    data = data.replace(/!\[\]\(\.\.\/img\//g, "![](/img/");
-    fs.writeFileSync(path.join(dest, path.basename(pathname)), data);
-  });
-} else {
-  let data = fs.readFileSync(src, "utf8");
-  data = fixMd(data, "blog");
-  data = data.replace(/!\[\]\(\.\.\/img\//g, "![](/img/");
-  fs.writeFileSync(dest, data);
-}
-
-console.log("Done.");
diff --git a/site2/website-next/migration-scripts/migrate-missing.js 
b/site2/website-next/migration-scripts/migrate-missing.js
deleted file mode 100644
index 9db85a6..0000000
--- a/site2/website-next/migration-scripts/migrate-missing.js
+++ /dev/null
@@ -1,3 +0,0 @@
-const fix = require("./fix-missing");
-const args = process.argv.slice(2);
-fix(args[0], args[1]);
diff --git a/site2/website-next/migration-scripts/migrate-override.js 
b/site2/website-next/migration-scripts/migrate-override.js
deleted file mode 100644
index cb13964..0000000
--- a/site2/website-next/migration-scripts/migrate-override.js
+++ /dev/null
@@ -1,3 +0,0 @@
-const fix = require("./override");
-const args = process.argv.slice(2);
-fix(args[0]);
diff --git a/site2/website-next/migration-scripts/migration.js 
b/site2/website-next/migration-scripts/migration.js
deleted file mode 100644
index 39302e2..0000000
--- a/site2/website-next/migration-scripts/migration.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const migrate = require("./migrate-chapter");
-
-const args = process.argv.slice(2);
-const version = args[0];
-const category = args[1];
-const prefix = args[2];
-
-migrate(version, category, prefix);
diff --git a/site2/website-next/migration-scripts/migration.sh 
b/site2/website-next/migration-scripts/migration.sh
deleted file mode 100644
index 69b4f3a..0000000
--- a/site2/website-next/migration-scripts/migration.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-version=2.7.3
-chapter="Cookbooks"
-prefix="cookbooks"
-
-node bak/migration.js $version "$chapter" $prefix fix
\ No newline at end of file
diff --git a/site2/website-next/migration-scripts/override.js 
b/site2/website-next/migration-scripts/override.js
deleted file mode 100644
index b75d118..0000000
--- a/site2/website-next/migration-scripts/override.js
+++ /dev/null
@@ -1,44 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-const _ = require("lodash");
-const fixMd = require("./fix-md");
-
-function travel(dir, callback) {
-  fs.readdirSync(dir).forEach((file) => {
-    var pathname = path.join(dir, file);
-    if (fs.statSync(pathname).isDirectory()) {
-      // travel(pathname, callback);
-      // } else if (file == "tiered-storage-filesystem.md") {
-    } else {
-      callback(pathname);
-    }
-  });
-}
-
-function fix(version) {
-  let version_full = "version-" + version;
-  let src = "../../website/versioned_docs/" + version_full;
-  let dest = "../../website-next/versioned_docs/" + version_full;
-  if (version == "next") {
-    src = "../../docs";
-    dest = "../../website-next/docs";
-  }
-  src = path.join(__dirname, src);
-  dest = path.join(__dirname, dest);
-
-  travel(src, function (pathname) {
-    let filename = path.basename(pathname);
-    try {
-      fs.statSync(dest);
-    } catch {
-      fs.mkdirSync(dest);
-    }
-    console.log(filename);
-    let data = fs.readFileSync(pathname, "utf8");
-    data = fixMd(data, version);
-    // filename = filename == "deploy-dcos.md" ? "deploy-docs.md" : filename;
-    fs.writeFileSync(path.join(dest, filename), data);
-  });
-}
-
-module.exports = fix;

Reply via email to