Separated the modern theme script into it's own file.

This commit is contained in:
Miguel Astor
2026-03-03 03:56:39 -04:00
parent b56b7176a8
commit afd11fba3a
9 changed files with 712 additions and 600 deletions

View File

@@ -36,6 +36,12 @@ def load_template(template_file: str) -> str:
return template_path.read_text(encoding="utf-8")
def load_script(script_file: str) -> str:
"""Load the JS script from the specified file."""
script_path = SCRIPT_DIR / script_file
return script_path.read_text(encoding="utf-8")
def load_asset_as_base64(path: Path, mime_type: str) -> str:
"""Load a file and return it as a base64 data URL."""
if path.exists():
@@ -117,10 +123,14 @@ def generate_report(db_path: str, output_path: str, top_n: int, assets_dir: str,
theme_css = get_theme_css(style)
theme_config = get_theme_config(style)
# Inject javascript
javascript = load_script('templates/script.js')
javascript = javascript.replace("__ALL_GAMES__", json.dumps(all_games))
javascript = javascript.replace("__TOP_N__", str(top_n))
javascript = javascript.replace("__THEME_CONFIG__", theme_config)
html = html.replace("__THEME_CSS__", theme_css)
html = html.replace("__THEME_CONFIG__", theme_config)
html = html.replace("__ALL_GAMES__", json.dumps(all_games))
html = html.replace("__TOP_N__", str(top_n))
html = html.replace("__SCRIPT__", javascript)
html = html.replace("__TOTAL_LIBRARY__", str(total_library))
html = html.replace("__BACKGROUND_IMAGE__", background_image)
html = html.replace("__BACKGROUND_IMAGE_CUSTOM__", background_image_custom)