From baca1da654a4f8f0ce2c013ad2c355c05cc57bf3 Mon Sep 17 00:00:00 2001 From: czhen <56986964+shczhen@users.noreply.github.com> Date: Fri, 24 Feb 2023 16:16:29 +0800 Subject: [PATCH 1/4] add replaceCustomContentStream --- .github/workflows/update.yml | 18 ++++++++++------ packages/content/index.js | 40 +++++++++++++++++++++++++----------- packages/download/index.js | 6 +++++- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 4772e18e07..3d11b01862 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -52,17 +52,23 @@ jobs: then yarn download ${{ inputs.repo }} en --ref ${{ inputs.branch }} yarn download ${{ inputs.repo }} zh --ref ${{ inputs.branch }} - else - yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} - fi - - # handle tidb-cloud doc based on specified en/ja doc branch - if [ ${{ inputs.repo }} = "pingcap/docs" ] && [ ${{ inputs.branch }} = "release-6.5" ] + # Update en TiDB Cloud doc based on specified doc branch + elif [ ${{ inputs.repo }} = "pingcap/docs" ] && [ ${{ inputs.branch }} = "release-6.5" ] then + # Remove TiDB Cloud CustomContent from TiDB doc + yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb yarn download:tidb-cloud:en --ref ${{ inputs.branch }} + # Re-download TiDB doc and remove TiDB Cloud CustomContent + yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb-cloud + # Update ja TiDB Cloud doc based on specified doc branch elif [ ${{ inputs.repo }} = "pingcap/docs" ] && [ ${{ inputs.branch }} = "i18n-ja-release-6.5" ] then + yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb yarn download:tidb-cloud:ja --ref ${{ inputs.branch }} + # Re-download TiDB doc and remove TiDB Cloud CustomContent + yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb-cloud + else + yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb-cloud fi - name: Update all folder diff --git a/packages/content/index.js b/packages/content/index.js index 6ab767d8db..29618daa2c 100644 --- a/packages/content/index.js +++ b/packages/content/index.js @@ -1,9 +1,13 @@ -const replaceStream = require('replacestream') +const replaceStream = require("replacestream"); -const frontMatter = /^---(.|\n)*---\n/ -const media = /\(\/?media\//g -const copyable = /{{< copyable\s+(.+)\s+>}}\r?\n/g -const tabsPanel = /{{< tabs-panel\s+(.+)\s+>}}\n/g +const frontMatter = /^---(.|\n)*---\n/; +const media = /\(\/?media\//g; +const copyable = /{{< copyable\s+(.+)\s+>}}\r?\n/g; +const tabsPanel = /{{< tabs-panel\s+(.+)\s+>}}\n/g; +const customContentTidb = + /(.|\n)*?<\/CustomContent>\n/g; +const customContentTidbCloud = + /(.|\n)*?<\/CustomContent>\n/g; /** * Replace front matter. @@ -13,27 +17,38 @@ const tabsPanel = /{{< tabs-panel\s+(.+)\s+>}}\n/g * @return {string} */ function replaceFrontMatter(str, replaced) { - return str.replace(frontMatter, replaced) + return str.replace(frontMatter, replaced); } function replaceImagePath(str, replaced) { - return str.replace(media, `(${replaced}/`) + return str.replace(media, `(${replaced}/`); } function replaceCopyable(str, replaced) { - return str.replace(copyable, replaced) + return str.replace(copyable, replaced); } function replaceImagePathStream(replaced) { - return replaceStream(media, `(${replaced}/`) + return replaceStream(media, `(${replaced}/`); } function replaceCopyableStream() { return replaceStream(copyable, function (_, p1) { // return `\n` // ! WithCopy is deprecated! - return `` - }) + return ``; + }); +} + +function replaceCustomContentStream(type) { + if (type === "tidb-cloud") { + return replaceStream(customContentTidbCloud, function (_, p1) { + return ``; + }); + } + return replaceStream(customContentTidb, function (_, p1) { + return ``; + }); } module.exports = { @@ -43,4 +58,5 @@ module.exports = { replaceStream, replaceImagePathStream, replaceCopyableStream, -} + replaceCustomContentStream, +}; diff --git a/packages/download/index.js b/packages/download/index.js index a512f74715..d7173d905b 100644 --- a/packages/download/index.js +++ b/packages/download/index.js @@ -10,6 +10,7 @@ import { import { replaceCopyableStream, replaceImagePathStream, + replaceCustomContentStream, } from "@pingcap/docs-content"; import { execSync } from "child_process"; @@ -53,7 +54,7 @@ function renameDoc(repo) { } export function download(argv) { - const { repo, path, ref, destination, config, dryRun } = argv; + const { repo, path, ref, destination, config, dryRun, rmCustomContent } = argv; const dest = nPath.resolve(destination); const options = genOptions(repo, config, dryRun); @@ -76,6 +77,9 @@ export function download(argv) { ); break; case "pingcap/docs": + if (rmCustomContent) { + options.pipelines.push(() => replaceCustomContentStream(rmCustomContent)); + } if (ref.startsWith("i18n-")) { const refDataList = ref.split("-"); refDataList.shift(); From 38ad68b0024f4df5461a5b6860c77aa9c4af4cde Mon Sep 17 00:00:00 2001 From: czhen <56986964+shczhen@users.noreply.github.com> Date: Mon, 27 Feb 2023 16:24:22 +0800 Subject: [PATCH 2/4] refine workflow --- .github/workflows/update.yml | 4 ++-- packages/download/index.js | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 3d11b01862..3608111535 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -56,14 +56,14 @@ jobs: elif [ ${{ inputs.repo }} = "pingcap/docs" ] && [ ${{ inputs.branch }} = "release-6.5" ] then # Remove TiDB Cloud CustomContent from TiDB doc - yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb + # yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb yarn download:tidb-cloud:en --ref ${{ inputs.branch }} # Re-download TiDB doc and remove TiDB Cloud CustomContent yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb-cloud # Update ja TiDB Cloud doc based on specified doc branch elif [ ${{ inputs.repo }} = "pingcap/docs" ] && [ ${{ inputs.branch }} = "i18n-ja-release-6.5" ] then - yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb + # yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb yarn download:tidb-cloud:ja --ref ${{ inputs.branch }} # Re-download TiDB doc and remove TiDB Cloud CustomContent yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }} --rm-custom-content tidb-cloud diff --git a/packages/download/index.js b/packages/download/index.js index d7173d905b..8507ee46f3 100644 --- a/packages/download/index.js +++ b/packages/download/index.js @@ -54,7 +54,8 @@ function renameDoc(repo) { } export function download(argv) { - const { repo, path, ref, destination, config, dryRun, rmCustomContent } = argv; + const { repo, path, ref, destination, config, dryRun, rmCustomContent } = + argv; const dest = nPath.resolve(destination); const options = genOptions(repo, config, dryRun); @@ -78,7 +79,9 @@ export function download(argv) { break; case "pingcap/docs": if (rmCustomContent) { - options.pipelines.push(() => replaceCustomContentStream(rmCustomContent)); + options.pipelines.push(() => + replaceCustomContentStream(rmCustomContent) + ); } if (ref.startsWith("i18n-")) { const refDataList = ref.split("-"); @@ -291,6 +294,7 @@ export function filterCloud(argv) { nPath.resolve(dest, `${lang}/tidbcloud/master`) ); rimraf.sync(docsDestPath); + options.pipelines.push(() => replaceCustomContentStream("tidb-cloud")); retrieveCloudMDsFromZip( { repo, From 88841cf484e83c618bb5c5e57f706f016fb34e51 Mon Sep 17 00:00:00 2001 From: czhen <56986964+shczhen@users.noreply.github.com> Date: Mon, 27 Feb 2023 16:31:45 +0800 Subject: [PATCH 3/4] Update index.js --- packages/download/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/download/index.js b/packages/download/index.js index 8507ee46f3..f064c3a66b 100644 --- a/packages/download/index.js +++ b/packages/download/index.js @@ -294,7 +294,7 @@ export function filterCloud(argv) { nPath.resolve(dest, `${lang}/tidbcloud/master`) ); rimraf.sync(docsDestPath); - options.pipelines.push(() => replaceCustomContentStream("tidb-cloud")); + options.pipelines.push(() => replaceCustomContentStream("tidb")); retrieveCloudMDsFromZip( { repo, From da56785b3dba77947a5948ddf438333dd5d1403b Mon Sep 17 00:00:00 2001 From: czhen <56986964+shczhen@users.noreply.github.com> Date: Mon, 27 Feb 2023 16:43:17 +0800 Subject: [PATCH 4/4] Update index.js --- packages/download/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/download/index.js b/packages/download/index.js index f064c3a66b..5da1d245e3 100644 --- a/packages/download/index.js +++ b/packages/download/index.js @@ -230,6 +230,7 @@ export function sync(argv) { case "pingcap/docs-dm": case "pingcap/docs-tidb-operator": const name = renameDoc(repo); + options.pipelines.push(() => replaceCustomContentStream("tidb-cloud")); handleSync( {