Skip to content

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

shhdgit
Copy link
Member

@shhdgit shhdgit commented Aug 5, 2025

First-time contributors' checklist

What is changed, added or deleted? (Required)

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)

What is the related PR or file link(s)?

  • This PR is translated from:
  • Other reference link(s):

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

Copy link

ti-chi-bot bot commented Aug 5, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kissmydb for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added missing-translation-status This PR does not have translation status info. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 5, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @shhdgit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a refactoring effort to consolidate and standardize the handling of Table of Contents (TOC) files specifically for cloud documentation. The core change involves centralizing the definition of relevant cloud TOC files and updating various JavaScript scripts to consistently process and filter documents based on this consolidated list. This significantly improves the maintainability and robustness of the documentation build process.

Highlights

  • Consolidated TOC File List Definition: A new CLOUD_TOC_LIST constant has been introduced across scripts/filterCloudDoc.js, scripts/filterCloudInitFiles.js, and scripts/filterNonCloudDoc.js. This centralizes the definition of all relevant cloud Table of Contents (TOC) markdown files, improving consistency and maintainability.
  • Refactored Cloud Document Filtering Logic: The main function in scripts/filterCloudDoc.js was updated to iterate through the newly defined CLOUD_TOC_LIST. It now collects all markdown links from each specified TOC file using getAllMdList, flattens the aggregated lists, and deduplicates the entries to ensure comprehensive processing of all cloud-related documents.
  • Streamlined Cloud Initialization File Processing: In scripts/filterCloudInitFiles.js, the previous manual reading and regex-based extraction of links from a single TOC file have been replaced. The script now efficiently gathers and deduplicates all relevant file paths from multiple cloud TOCs by leveraging the getAllMdList utility function and the CLOUD_TOC_LIST.
  • Enhanced Non-Cloud Document Exclusion: The extractFilefromList function within scripts/filterNonCloudDoc.js has been modified. Instead of checking for a single specific TOC file (TOC-tidb-cloud.md), the filtering logic now correctly identifies and skips all files present in the CLOUD_TOC_LIST, ensuring accurate exclusion of all designated cloud TOCs.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively refactors the scripts to handle multiple cloud documentation TOC files, which is a great improvement. My main feedback focuses on further improving maintainability by centralizing the new CLOUD_TOC_LIST constant. Currently, it's duplicated across three files. Moving it to a single shared location like utils.js will make future updates much simpler and less error-prone. I've also included a couple of minor suggestions to remove redundant code comments.

Comment on lines 27 to 31
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";

Comment on lines 5 to 9
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.

Comment on lines 8 to 12
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.

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)];

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)];

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 5, 2025
@lilin90 lilin90 added rename-serverless This PR is caused by renaming TiDB Cloud Serverless. translation/no-need No need to translate this PR. labels Aug 5, 2025
@ti-chi-bot ti-chi-bot bot removed the missing-translation-status This PR does not have translation status info. label Aug 5, 2025
@lilin90 lilin90 changed the base branch from master to feature/preview-starter August 5, 2025 05:57
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 5, 2025
@lilin90 lilin90 added needs-cherry-pick-master Should cherry pick this PR to master branch. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 5, 2025
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 5, 2025
@lilin90 lilin90 changed the base branch from feature/preview-starter to master August 5, 2025 05:59
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tidb-cloud This PR relates to the area of TiDB Cloud. needs-cherry-pick-master Should cherry pick this PR to master branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. rename-serverless This PR is caused by renaming TiDB Cloud Serverless. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. translation/no-need No need to translate this PR. website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants