Fix duplicate icon assignment
This commit is contained in:
parent
ad28b6e81e
commit
4017b4ab72
211 changed files with 782 additions and 6 deletions
28
scripts/download_icons.py
Normal file
28
scripts/download_icons.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import json
|
||||
from urllib.request import urlopen, Request
|
||||
from pathlib import Path
|
||||
|
||||
ICON_LIST_URL = "https://cc0-icons.jonh.eu/icons.json"
|
||||
BASE_URL = "https://cc0-icons.jonh.eu/"
|
||||
|
||||
OUTPUT_DIR = Path(__file__).resolve().parent.parent / "static" / "icons"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
req = Request(ICON_LIST_URL, headers={"User-Agent": "Mozilla/5.0"})
|
||||
with urlopen(req) as resp:
|
||||
data = json.load(resp)
|
||||
icons = data.get("icons", [])
|
||||
for icon in icons:
|
||||
slug = icon.get("slug")
|
||||
url = BASE_URL + icon.get("url")
|
||||
path = OUTPUT_DIR / f"{slug}.svg"
|
||||
req = Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
||||
with urlopen(req) as resp:
|
||||
path.write_bytes(resp.read())
|
||||
print(f"Downloaded {len(icons)} icons to {OUTPUT_DIR}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
from typing import List, Dict, Optional
|
||||
|
||||
import yaml
|
||||
|
@ -54,6 +55,17 @@ def _save_json(path: Path, data: List[Dict]) -> None:
|
|||
path.write_text(json.dumps(data, indent=2))
|
||||
|
||||
|
||||
def _copy_icons() -> None:
|
||||
"""Copy vendored icons to the output directory."""
|
||||
src_dir = Path("static/icons")
|
||||
dst_dir = OUTPUT_DIR / "icons"
|
||||
if not src_dir.is_dir():
|
||||
return
|
||||
dst_dir.mkdir(parents=True, exist_ok=True)
|
||||
for icon in src_dir.glob("*.svg"):
|
||||
shutil.copy(icon, dst_dir / icon.name)
|
||||
|
||||
|
||||
def _render_snippet(report: Dict, out_dir: Path) -> None:
|
||||
"""Render a single report snippet to ``<name>.html`` inside ``out_dir``."""
|
||||
env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
|
||||
|
@ -106,6 +118,8 @@ def _generate_interval(interval: str, domain: Optional[str] = None) -> None:
|
|||
typer.echo("No report definitions found")
|
||||
return
|
||||
|
||||
_copy_icons()
|
||||
|
||||
bucket = _bucket_expr(interval)
|
||||
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
|
@ -153,6 +167,8 @@ def _generate_interval(interval: str, domain: Optional[str] = None) -> None:
|
|||
"json": f"{name}.json",
|
||||
"html": f"{name}.html",
|
||||
}
|
||||
if "icon" in definition:
|
||||
entry["icon"] = definition["icon"]
|
||||
if "color" in definition:
|
||||
entry["color"] = definition["color"]
|
||||
if "colors" in definition:
|
||||
|
@ -175,6 +191,7 @@ def _generate_all_domains(interval: str) -> None:
|
|||
|
||||
def _generate_root_index() -> None:
|
||||
"""Render the top-level index listing all intervals and domains."""
|
||||
_copy_icons()
|
||||
intervals = [
|
||||
p.name
|
||||
for p in OUTPUT_DIR.iterdir()
|
||||
|
@ -204,6 +221,8 @@ def _generate_global() -> None:
|
|||
typer.echo("No report definitions found")
|
||||
return
|
||||
|
||||
_copy_icons()
|
||||
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cur = conn.cursor()
|
||||
|
||||
|
@ -230,6 +249,8 @@ def _generate_global() -> None:
|
|||
"json": f"{name}.json",
|
||||
"html": f"{name}.html",
|
||||
}
|
||||
if "icon" in definition:
|
||||
entry["icon"] = definition["icon"]
|
||||
if "color" in definition:
|
||||
entry["color"] = definition["color"]
|
||||
if "colors" in definition:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue