Skip to content
13 changes: 12 additions & 1 deletion scripts/filterCloudDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ const extractFilefromList = (
});
};

const CLOUD_TOC_LIST = [
"TOC-tidb-cloud.md",
"TOC-tidb-cloud-essential.md",
"TOC-tidb-cloud-starter.md",
];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While it's great to consolidate the TOC file list, this CLOUD_TOC_LIST constant is now duplicated in filterCloudInitFiles.js and filterNonCloudDoc.js as well.

To avoid duplication and improve maintainability, this constant should be defined once in a shared file (e.g., scripts/utils.js) and then imported where needed. This follows the Don't Repeat Yourself (DRY) principle.

You would need to add the constant definition and export it from scripts/utils.js:

// In scripts/utils.js
export const CLOUD_TOC_LIST = [
  "TOC-tidb-cloud.md",
  "TOC-tidb-cloud-essential.md",
  "TOC-tidb-cloud-starter.md",
];

Then, you can import it here.

import { CLOUD_TOC_LIST } from "./utils.js";


const main = () => {
const filteredLinkList = getAllMdList("TOC-tidb-cloud.md");
// Get all MD lists from each TOC file and deduplicate
const allFilteredLinkLists = CLOUD_TOC_LIST.map((tocFile) =>
getAllMdList(tocFile)
);
const flattenedList = allFilteredLinkLists.flat();
const filteredLinkList = [...new Set(flattenedList)]; // Deduplicate

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The comment // Deduplicate is redundant here. The [...new Set()] syntax is a common and self-documenting JavaScript idiom for creating an array with unique values.

  const filteredLinkList = [...new Set(flattenedList)];


extractFilefromList(filteredLinkList, ".", "./tmp");
copySingleFileSync("TOC-tidb-cloud.md", "./tmp/TOC.md");
Expand Down
25 changes: 15 additions & 10 deletions scripts/filterCloudInitFiles.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import * as fs from "fs";
import path from "path";
import { getAllMdList } from "./utils.js";

// Read the TOC file
const tocContent = fs.readFileSync("TOC-tidb-cloud.md", "utf8");
const CLOUD_TOC_LIST = [
"TOC-tidb-cloud.md",
"TOC-tidb-cloud-essential.md",
"TOC-tidb-cloud-starter.md",
];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This CLOUD_TOC_LIST constant is duplicated across multiple scripts. To improve maintainability, it should be defined once in scripts/utils.js and imported.

Please remove this constant definition and instead modify the import on line 3 to:

import { getAllMdList, CLOUD_TOC_LIST } from "./utils.js";

You will also need to add the constant definition to scripts/utils.js and export it.


// Regular expression to match markdown links
const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
// Get all MD files from multiple TOCs and deduplicate
const allFilteredLinkLists = CLOUD_TOC_LIST.map((tocFile) =>
getAllMdList(tocFile)
);
const flattenedList = allFilteredLinkLists.flat();
const allFilePaths = [...new Set(flattenedList)]; // Deduplicate

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The // Deduplicate comment is redundant here, as the [...new Set()] syntax is a well-known JavaScript idiom for creating an array with unique values from an iterable.

Suggested change
const allFilePaths = [...new Set(flattenedList)]; // Deduplicate
const allFilePaths = [...new Set(flattenedList)];


// Set to store unique file paths
// Set to store filtered file paths
const filePaths = new Set();

// Extract all file paths from markdown links
let match;
while ((match = linkRegex.exec(tocContent)) !== null) {
const filePath = match[2];

// Filter the file paths
for (const filePath of allFilePaths) {
// Skip external links (starting with http/https)
if (filePath.startsWith("http")) {
continue;
Expand Down
8 changes: 7 additions & 1 deletion scripts/filterNonCloudDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import {
removeCustomContent,
} from "./utils.js";

const CLOUD_TOC_LIST = [
"TOC-tidb-cloud.md",
"TOC-tidb-cloud-essential.md",
"TOC-tidb-cloud-starter.md",
];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This CLOUD_TOC_LIST constant is duplicated across multiple scripts. To improve maintainability, it should be defined once in scripts/utils.js and imported.

Please remove this constant definition and instead add the following import at the top of the file with the other imports:

import { CLOUD_TOC_LIST } from "./utils.js";

You will also need to add the constant definition to scripts/utils.js and export it.


const contentHandler = (content = "") => {
return removeCustomContent("tidb", content);
};
Expand All @@ -17,7 +23,7 @@ const extractFilefromList = (
fileList.forEach((filePath = "") => {
if (
filePath.includes(`/tidb-cloud/`) ||
filePath.includes(`TOC-tidb-cloud.md`)
CLOUD_TOC_LIST.includes(filePath)
) {
return;
}
Expand Down
Loading