import os import json import gzip from string import Template from collections import defaultdict from fnmatch import fnmatch from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('.')) template = env.get_template('templates/index.j2') directory = '/data/html_data' # Change this to your directory path rocky_version = "8.10" def generate_sitemap(directory): links = defaultdict(lambda: defaultdict(dict)) for root, _, files in os.walk(directory): for file in files: full_filepath = os.path.join(root, file) filepath = full_filepath.split(rocky_version, 1)[-1] if any(fnmatch(filepath, pattern) for pattern in ['/index.html', '/links.html','/list.json*', '/sitemap*']): continue filepath_parts = filepath.split('/') package_name = filepath_parts[1] man_type = filepath_parts[2] man_type_number = man_type.lstrip('man') if man_type.startswith('man') else man_type command_file = filepath_parts[3] command = command_file.split('.html', 1)[0] if filepath.startswith('/'): filepath = filepath[1:] fullname = f"{package_name} - {command}({man_type_number})" links[package_name][command] = { "url": filepath, "man_type": man_type, "man_type_number": man_type_number, "fullname": fullname } return links def generate_links_html(links): links_html = "" for package_name in links.keys(): links_html += f"