commit c454887b80d6c89a4923b0f676baf60fc2c86cff
parent b00573d39a5042ec86553d71e8653acf6aa496ac
Author: Amit Dutta <amitdutta4255@gmail.com>
Date: Fri, 10 Oct 2025 21:10:14 +0530
fix: improve generate_index.py script robustness and path handling
Diffstat:
2 files changed, 69 insertions(+), 19 deletions(-)
diff --git a/docs/generate_index.py b/docs/generate_index.py
@@ -4,7 +4,7 @@ import os
# The root URL of your repository.
REPO_URL = "https://github.com/notamitgamer/bsc"
# List of directories to exclude from the list.
-EXCLUDED_DIRS = ['.git', '.github', 'MinGW64', 'print', 'docs']
+EXCLUDED_DIRS = ['.git', '.github', '.vscode', 'MinGW64', 'print', 'docs']
# List of files to exclude from the list.
EXCLUDED_FILES = ['index.html', 'README.md', 'CODE_OF_CONDUCT.md', 'CONTRIBUTING.md',
'LICENSE', 'main.js', 'package.json', 'SECURITY.md', 'server.js', 'template.html']
@@ -51,27 +51,39 @@ def generate_file_list():
def main():
"""Generates the final index.html from a template."""
- # --- THIS IS THE FIX ---
- # Define paths relative to the repository root, where the Action runs
- template_path = 'docs/template.html'
- output_path = 'docs/index.html'
-
+ # Get the directory of this script
+ script_dir = os.path.dirname(os.path.abspath(__file__))
+ repo_root = os.path.dirname(script_dir) # Go up one level from docs/
+
+ # Change to repo root directory for file walking
+ original_cwd = os.getcwd()
+ os.chdir(repo_root)
+
try:
- with open(template_path, 'r') as f:
- template = f.read()
- except FileNotFoundError:
- print(f"Error: The template file was not found at {template_path}")
- return
+ # Define paths relative to the script location
+ template_path = os.path.join(script_dir, 'template.html')
+ output_path = os.path.join(script_dir, 'index.html')
- file_list_html = generate_file_list()
-
- # Replace the placeholder with our generated list
- final_html = template.replace('<!--FILE_LIST_PLACEHOLDER-->', file_list_html)
+ try:
+ with open(template_path, 'r') as f:
+ template = f.read()
+ except FileNotFoundError:
+ print(f"Error: The template file was not found at {template_path}")
+ return
- with open(output_path, 'w') as f:
- f.write(final_html)
-
- print(f"{output_path} generated successfully.")
+ file_list_html = generate_file_list()
+
+ # Replace the placeholder with our generated list
+ final_html = template.replace('<!--FILE_LIST_PLACEHOLDER-->', file_list_html)
+
+ with open(output_path, 'w') as f:
+ f.write(final_html)
+
+ print(f"{output_path} generated successfully.")
+
+ finally:
+ # Always change back to original directory
+ os.chdir(original_cwd)
if __name__ == "__main__":
main()
diff --git a/docs/index.html b/docs/index.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>BSc Repository File Index</title>
+ <script src="https://cdn.tailwindcss.com"></script>
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
+ <style>
+ body {
+ font-family: 'Inter', sans-serif;
+ }
+ </style>
+</head>
+<body class="bg-gray-50">
+ <div class="container mx-auto px-4 py-8 md:py-16">
+ <div class="max-w-4xl mx-auto bg-white rounded-2xl shadow-lg overflow-hidden">
+ <div class="p-8">
+ <div class="text-center mb-8">
+ <h1 class="text-3xl md:text-4xl font-bold text-gray-800">BSc Repository Contents</h1>
+ <p class="text-gray-500 mt-2">A quick navigation guide to the files in the repository. This list is auto-generated.</p>
+ </div>
+ <div class="space-y-4">
+ <h2 class="text-lg font-semibold text-gray-700 border-b pb-2">Files and Folders</h2>
+ <ul class="space-y-3">
+ <li><a href="https://github.com/notamitgamer/bsc/tree/main/c" target="_blank" class="flex items-center p-4 bg-gray-100 hover:bg-blue-100 rounded-lg transition-colors duration-200"><svg class="w-6 h-6 text-blue-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"></path></svg><span class="font-medium text-gray-800">c</span><span class="ml-auto text-blue-500 font-semibold text-sm">View on GitHub →</span></a></li>
+<li><a href="https://github.com/notamitgamer/bsc/tree/main/letusc" target="_blank" class="flex items-center p-4 bg-gray-100 hover:bg-blue-100 rounded-lg transition-colors duration-200"><svg class="w-6 h-6 text-blue-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"></path></svg><span class="font-medium text-gray-800">letusc</span><span class="ml-auto text-blue-500 font-semibold text-sm">View on GitHub →</span></a></li>
+<li><a href="https://github.com/notamitgamer/bsc/tree/main/tuition-c" target="_blank" class="flex items-center p-4 bg-gray-100 hover:bg-blue-100 rounded-lg transition-colors duration-200"><svg class="w-6 h-6 text-blue-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"></path></svg><span class="font-medium text-gray-800">tuition-c</span><span class="ml-auto text-blue-500 font-semibold text-sm">View on GitHub →</span></a></li>
+ </ul>
+ </div>
+ </div>
+ <footer class="text-center py-4 bg-gray-100 border-t">
+ <p class="text-sm text-gray-500">This page is an index for the <a href="https://github.com/notamitgamer/bsc" class="text-blue-600 hover:underline">bsc repository</a>.</p>
+ </footer>
+ </div>
+ </div>
+</body>
+</html>