From 5a5193033bb9fca13916161351e0bc0ae57ff6cc Mon Sep 17 00:00:00 2001 From: Kelvin Nguyen Date: Thu, 12 Dec 2024 14:25:08 -0800 Subject: [PATCH] Update generate_index to include relative path --- generate_index.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/generate_index.py b/generate_index.py index 72c5b7c..b97ee9a 100644 --- a/generate_index.py +++ b/generate_index.py @@ -13,22 +13,24 @@ def generate_index(dir_path): files = sorted(os.listdir(dir_path)) - # Get the name of the directory for the heading - dir_name = os.path.dirname(dir_path).replace(base_dir, "") + # Get the full relative path of the directory for the heading + dir_relative_path = os.path.relpath(dir_path, base_dir).replace(os.sep, "/") # Create index.html file with a heading and a "Go to Parent Directory" link index_content = f'' # Add a link to go to the parent directory - parent_dir_url = os.path.dirname(dir_path).replace(base_dir, "").replace(os.sep, "/") - if parent_dir_url != "": + parent_dir_url = os.path.dirname(dir_path) + if parent_dir_url != base_dir: + # Use `..` to go one level up from the current directory index_content += f'

.. (Parent Directory)

' - + if dir_path != base_dir and dir_path.split("_")[-1].isdigit(): if int(dir_path.split("_")[-1]) < 2000: index_content += '

Destination MGRA in red; MGRA or TAZ w access in blue.

' + # Add the heading for the current directory - index_content += f'

Index of {dir_name}