-
Notifications
You must be signed in to change notification settings - Fork 702
refactor: consolidate TOC file handling in cloud document scripts #21511
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
f2a10a2
153ee21
0ca46d9
5985734
860bcd7
ea08a0b
8ec9ed2
6fbd149
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,19 @@ const extractFilefromList = ( | |
}); | ||
}; | ||
|
||
const CLOUD_TOC_LIST = [ | ||
"TOC-tidb-cloud.md", | ||
"TOC-tidb-cloud-essential.md", | ||
"TOC-tidb-cloud-starter.md", | ||
]; | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
extractFilefromList(filteredLinkList, ".", "./tmp"); | ||
copySingleFileSync("TOC-tidb-cloud.md", "./tmp/TOC.md"); | ||
|
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", | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This 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 |
||
|
||
// 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// 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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This 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 |
||
|
||
const contentHandler = (content = "") => { | ||
return removeCustomContent("tidb", content); | ||
}; | ||
|
@@ -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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it's great to consolidate the TOC file list, this
CLOUD_TOC_LIST
constant is now duplicated infilterCloudInitFiles.js
andfilterNonCloudDoc.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
:Then, you can import it here.