import json import os from urllib.parse import quote # HTML-шаблон для страниц игроков PLAYER_TEMPLATE = """ {title}

Legends of Hockey

{article} {name}
""" # Шаблон для главной страницы INDEX_TEMPLATE = """ Legends of Hockey

Legends of Hockey

Drop the puck and dive into hockey history! This site celebrates the skill, grit, and unforgettable moments of legendary players who made the game on ice truly iconic.

""" def generate_static_site(): # Список игроков из папки data data_dir = "data" players = [f.replace('.json', '') for f in os.listdir(data_dir) if f.endswith('.json')] # Создаём папку для статических файлов, если её нет output_dir = "static_site" if not os.path.exists(output_dir): os.makedirs(output_dir) # Генерируем навигационные ссылки для всех страниц nav_links = "".join([f'{player.replace("-", " ").title()}' for player in players]) # Генерируем страницу для каждого игрока for player in players: with open(os.path.join(data_dir, f"{player}.json"), 'r', encoding='utf-8') as f: data = json.load(f) # Заполняем шаблон данными игрока player_html = PLAYER_TEMPLATE.format( title=data["title"], description=data["description"], keywords=", ".join(data["keywords"]), canonical=data["canonical"].replace('#', ''), nav_links=nav_links, article=data["article"], image=data["image"], name=data["name"] ) # Сохраняем HTML-файл output_file = os.path.join(output_dir, f"{player}.html") with open(output_file, 'w', encoding='utf-8') as f: f.write(player_html) print(f"Сгенерирована страница: {output_file}") # Генерируем главную страницу (index.html) index_html = INDEX_TEMPLATE.format(nav_links=nav_links) with open(os.path.join(output_dir, "index.html"), 'w', encoding='utf-8') as f: f.write(index_html) print("Сгенерирована главная страница: static_site/index.html") if __name__ == "__main__": generate_static_site()