Fix sitemap generation: Use correct config per ENV and prefix Git URLs
authorShane Jaroch <chown_tee@proton.me>
Wed, 21 Jan 2026 01:44:48 +0000 (20:44 -0500)
committerShane Jaroch <chown_tee@proton.me>
Wed, 21 Jan 2026 01:44:48 +0000 (20:44 -0500)
Makefile
scripts/gen_services_map.py

index b85101d7d42156633157b3b410d7613b02d6e035..43685ef82926f3b54b1b7e59853aa734b60d99a7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -58,7 +58,7 @@ VPS := $(VPS_USER)@$(VPS_HOST)
 .PHONY: stage/nginx
 stage/nginx: ##H @Remote Stage files on the remote VPS
        @echo "Staging files on $(VPS_HOST) (ENV=$(ENV))..."
-       python3 scripts/gen_services_map.py
+       python3 scripts/gen_services_map.py etc/nginx/conf.d/default.$(ENV).conf
        ssh $(VPS) 'rm -rf ~/.nginx-staging && mkdir -p ~/.nginx-staging/etc/nginx/conf.d ~/.nginx-staging/scripts/gitweb-simplefrontend'
        scp -q -r etc/nginx/conf.d/*.conf $(VPS):~/.nginx-staging/etc/nginx/conf.d/
        scp -q etc/gitweb.conf $(VPS):~/.nginx-staging/etc/gitweb.conf
index c5bc36387bdb837976090a58442f78ca07bf1f7b..5b4270f013ab1635644c78a9e65cc6ed9e9b8346 100755 (executable)
@@ -64,31 +64,45 @@ def parse_file(path, pattern, is_version=False):
     return items
 
 
-def get_all_services():
+import sys
+import argparse
+
+def get_all_services(custom_config_path=None):
     # Regex to find "Version X: Description" lines
     version_pattern = re.compile(r"^\s*#\s*Version\s+(\w+):\s*(.+)$", re.MULTILINE)
     service_pattern = re.compile(r"^\s*#\s*Service:\s*(.+?)\s*\|\s*(.+)$", re.MULTILINE)
 
     services_git = parse_file(NGINX_CONF, version_pattern, is_version=True)
 
-    # Locate default.conf
-    # On Server: Read the live deployed config
-    live_default = Path("/etc/nginx/conf.d/default.conf")
-    # On Local: Read default.dev.conf
-    local_dev = REPO_ROOT / "etc/nginx/conf.d/default.dev.conf"
-
-    if live_default.exists():
-        DEFAULT_CONF = live_default
-        print(f"Using live config: {DEFAULT_CONF}")
+    DEFAULT_CONF = None
+    if custom_config_path:
+        p = Path(custom_config_path)
+        if p.exists():
+            DEFAULT_CONF = p
+            print(f"Using custom config: {DEFAULT_CONF}")
+        else:
+            print(f"Error: Custom config not found at {p}")
+            sys.exit(1)
     else:
-        DEFAULT_CONF = local_dev
-        print(f"Using local config: {DEFAULT_CONF}")
+        # Locate default.conf fallback (old logic)
+        # On Server: Read the live deployed config
+        live_default = Path("/etc/nginx/conf.d/default.conf")
+        # On Local: Read default.dev.conf
+        local_dev = REPO_ROOT / "etc/nginx/conf.d/default.dev.conf"
+
+        if live_default.exists():
+            DEFAULT_CONF = live_default
+            print(f"Using live config: {DEFAULT_CONF}")
+        else:
+            DEFAULT_CONF = local_dev
+            print(f"Using local config: {DEFAULT_CONF}")
 
     services_other = parse_file(DEFAULT_CONF, service_pattern, is_version=False)
 
     return services_git, services_other
 
 
+
 def generate_html(title, groups):
     """
     groups: list of tuples (header_name, services_list)
@@ -111,9 +125,19 @@ def generate_html(title, groups):
     return HTML_TEMPLATE.format(title=title, content=content_html)
 
 
+
 def main():
+    parser = argparse.ArgumentParser(description="Generate HTML services map from Nginx config")
+    parser.add_argument("config_path", nargs="?", help="Path to the Nginx configuration file")
+    args = parser.parse_args()
+
     print(f"Reading configs...")
-    services_git, services_other = get_all_services()
+    services_git, services_other = get_all_services(args.config_path)
+
+    # Prefix Git services with the correct domain
+    for s in services_git:
+        if s["url"].startswith("/"):
+            s["url"] = f"https://git.nutra.tk{s['url']}"
 
     # Output 1: Git Services Only
     print(f"Generating Git Services map with {len(services_git)} items...")
@@ -147,3 +171,4 @@ def main():
 
 if __name__ == "__main__":
     main()
+