From 2719e6095268c8a5ca6051343d8f9a5e1a1006f5 Mon Sep 17 00:00:00 2001 From: Kelvin Nguyen Date: Thu, 12 Dec 2024 09:12:07 -0800 Subject: [PATCH] Update generate index to have rel path Fixes #2 --- generate_index.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/generate_index.py b/generate_index.py index 72c5b7c..b5aa0a8 100644 --- a/generate_index.py +++ b/generate_index.py @@ -13,22 +13,25 @@ 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 != "": - index_content += f'

.. (Parent Directory)

' - + parent_dir_url = os.path.dirname(dir_path) + if parent_dir_url != base_dir: + # Calculate relative path to parent directory + parent_dir_relative = os.path.relpath(parent_dir_url, base_dir).replace(os.sep, "/") + 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}