From c8aecd0ba19591a9c104393e4c9e2d5e6da5f199 Mon Sep 17 00:00:00 2001 From: matchy233 <matchy233@gmail.com> Date: Wed, 10 Jul 2024 16:07:49 -0400 Subject: [PATCH] fix(toc): pytoc correctly handles empty subdir --- scripts/autogen-toc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/autogen-toc.py b/scripts/autogen-toc.py index 0c8fbb2..44573bf 100644 --- a/scripts/autogen-toc.py +++ b/scripts/autogen-toc.py @@ -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] @@ -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()