Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add replaceCustomContentStream #24

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 28 additions & 12 deletions packages/content/index.js
Original file line number Diff line number Diff line change
@@ -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 =
/<CustomContent +platform=["']tidb["'] *>(.|\n)*?<\/CustomContent>\n/g;
const customContentTidbCloud =
/<CustomContent +platform=["']tidb-cloud["'] *>(.|\n)*?<\/CustomContent>\n/g;

/**
* Replace front matter.
Expand All @@ -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 `<WithCopy tag=${p1} />\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 = {
Expand All @@ -43,4 +58,5 @@ module.exports = {
replaceStream,
replaceImagePathStream,
replaceCopyableStream,
}
replaceCustomContentStream,
};
11 changes: 10 additions & 1 deletion packages/download/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
replaceCopyableStream,
replaceImagePathStream,
replaceCustomContentStream,
} from "@pingcap/docs-content";

import { execSync } from "child_process";
Expand Down Expand Up @@ -53,7 +54,8 @@ 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);

Expand All @@ -76,6 +78,11 @@ 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();
Expand Down Expand Up @@ -223,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(
{
Expand Down Expand Up @@ -287,6 +295,7 @@ export function filterCloud(argv) {
nPath.resolve(dest, `${lang}/tidbcloud/master`)
);
rimraf.sync(docsDestPath);
options.pipelines.push(() => replaceCustomContentStream("tidb"));
retrieveCloudMDsFromZip(
{
repo,
Expand Down