Skip to content

feat: add script to generate table of contents #263

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

Merged
merged 1 commit into from
Jun 7, 2024
Merged

feat: add script to generate table of contents #263

merged 1 commit into from
Jun 7, 2024

Conversation

yangshun
Copy link
Contributor

@yangshun yangshun commented Jun 3, 2024

Motivation

Manually maintaining the table of contents is a chore. When a new question is added, the table of contents has to be manually updated with number, title and slug. If the title changes, the TOC has to be updated again. This can easily go out of sync.

Implementation

I added a script to generate the table of contents based on the questions. As much as possible, the script leaves the contents alone. The script works as follows:

  1. It clears out the table of contents (between the TOC_START and TOC_END markers)
  2. Process the list of questions (between the QUESTIONS_START and QUESTIONS_END markers) and collect the list of questions
  • While doing this, if there are incorrect/non-sequential numbers, the script will rename it for you.
  1. Generate the table of contents markdown using the list of processed questions. The slugs are generated using github-slugger, it should be mostly the same as how GitHub slugify the titles.
  2. Combined the sections back into a single file and write to disk.

The script can be executed by running npm run gen.

Results

Through using the generation script, it has found some misnumbered qns (e.g. 445 should be 443). You can check the result on the branch of my fork here, so far seems fine.

@yangshun
Copy link
Contributor Author

yangshun commented Jun 4, 2024

@sudheerj I've rebased and resolved merge conflicts

@sudheerj
Copy link
Owner

sudheerj commented Jun 7, 2024

@yangshun I really appreciate for the generation script of TOC. It is helpful to avoid syncing issues between TOC and answers. Thank you.

@sudheerj sudheerj merged commit aa1ef0f into sudheerj:master Jun 7, 2024
@yangshun yangshun deleted the ys/gen-toc branch June 7, 2024 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants