sudheerj / javascript-interview-questions

List of 1000 JavaScript Interview Questions
24.33k stars 6.92k forks source link

feat: add script to generate table of contents #263

Closed yangshun closed 5 months ago

yangshun commented 5 months ago

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.
  3. 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.
  4. 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 commented 5 months ago

@sudheerj I've rebased and resolved merge conflicts

sudheerj commented 5 months ago

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