From d0e2c632291751fe77a20143d3de20c9366711cc Mon Sep 17 00:00:00 2001 From: Bhargava Sana Date: Mon, 2 Dec 2024 17:30:33 -0800 Subject: [PATCH] Avoig generating index file in .github folder --- generate_index.py | 60 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/generate_index.py b/generate_index.py index a839577..c95a7f6 100644 --- a/generate_index.py +++ b/generate_index.py @@ -1,24 +1,46 @@ import os -# Define the root directory (your GitHub Pages root folder) -root_dir = './' +# Define the base directory (e.g., your repository root) +base_dir = "./" -# Walk through all directories and subdirectories -for root, dirs, files in os.walk(root_dir): - # Skip the root directory itself to avoid creating index.html at the root - if root == root_dir: - continue +# Function to generate index.html for a given folder +def generate_index(dir_path): + # Avoid generating index in .github folder + if ".github" in dir_path: + return - # Check if the directory contains files - if files: - # Define the index.html file path for the folder - index_file_path = os.path.join(root, 'index.html') + files = os.listdir(dir_path) + + # Skip if the directory is empty + if not files: + return + + # Create index.html file + index_content = '

Directory Listing

' + + # Write the generated content to index.html in the folder + with open(os.path.join(dir_path, 'index.html'), 'w') as index_file: + index_file.write(index_content) + +# Function to walk through directories and generate index files +def walk_directory(directory): + # Iterate through the subdirectories and generate index files + for dirpath, dirnames, filenames in os.walk(directory): + # Avoid the .github folder and other unwanted folders + if ".github" in dirpath: + continue + + generate_index(dirpath) + +# Call the function to walk the directory structure and generate index.html files +walk_directory(base_dir)