Skip to content

Commit

Permalink
fix(toc): pytoc correctly handles empty subdir
Browse files Browse the repository at this point in the history
  • Loading branch information
matchy233 committed Jul 10, 2024
1 parent c8f036a commit c8aecd0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/autogen-toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def titlize(word, fname):

def generate_toc(dir, sub_dir):
toc = ""
main_file = ""
for file in os.listdir(os.path.join(dir, sub_dir)):
if file[0].isdigit():
fname = [x for x in file[2:].replace('.md', '').split('_') if x]
Expand All @@ -83,6 +84,9 @@ def generate_toc(dir, sub_dir):
main_file = file
else:
continue
# do nothing if main_file is not found (i.e. no file needs TOC)
if main_file == "":
return
main_file_path = os.path.join(dir, sub_dir, main_file)
with open(main_file_path, "r") as f:
content = f.read()
Expand Down

0 comments on commit c8aecd0

Please sign in to comment.