From e70d3888e0b8c05160c19f279061c31a64d1086f Mon Sep 17 00:00:00 2001 From: Royalpriest Babalola <88779808+royalpriest@users.noreply.github.com> Date: Sat, 7 Nov 2026 17:18:08 -0500 Subject: [PATCH] Fix invalid favicon SVG and serve a versioned train icon --- app.py | 10 ++++++++++ assets/favicon.svg | 1 + assets/railstat-mark.svg | 2 +- report_tool/templates/_theme.html | 6 +++++- tests/test_app.py | 16 ++++++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 assets/favicon.svg diff --git a/app.py b/app.py index 458a5dd..4ab4daf 100644 --- a/app.py +++ b/app.py @@ -175,6 +175,16 @@ def build_report(data: bytes, source: str, show_names: bool) -> Response | tuple return report_response(result, source, data, show_names) +@app.get("/favicon.svg") +def favicon(): + """Serve a browser-readable icon at a stable, directly inspectable URL.""" + return send_file( + Path(__file__).parent / "assets" / "favicon.svg", + mimetype="image/svg+xml", + max_age=3600, + ) + + @app.get("/") def index(): return landing_page() diff --git a/assets/favicon.svg b/assets/favicon.svg new file mode 100644 index 0000000..b604ea4 --- /dev/null +++ b/assets/favicon.svg @@ -0,0 +1 @@ + diff --git a/assets/railstat-mark.svg b/assets/railstat-mark.svg index 86e944b..c6d3afc 100644 --- a/assets/railstat-mark.svg +++ b/assets/railstat-mark.svg @@ -1 +1 @@ - + diff --git a/report_tool/templates/_theme.html b/report_tool/templates/_theme.html index 3edc20a..39c5e2f 100644 --- a/report_tool/templates/_theme.html +++ b/report_tool/templates/_theme.html @@ -1,5 +1,9 @@ {# Shared look: warm paper, light modular accents, light/dark tokens, and the theme switcher. Included in . #} - +{% if request is defined %} + +{% else %} + +{% endif %} diff --git a/tests/test_app.py b/tests/test_app.py index 91580e3..a9f4eb0 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -96,3 +96,19 @@ def test_too_large(client, monkeypatch): response = upload(client, b"x" * 100) assert response.status_code == 413 assert b"larger than" in response.data + + +def test_favicon_is_valid_svg(): + import xml.etree.ElementTree as ET + + response = app.test_client().get("/favicon.svg?v=2") + assert response.status_code == 200 + assert response.mimetype == "image/svg+xml" + root = ET.fromstring(response.data) + assert root.tag == "{http://www.w3.org/2000/svg}svg" + assert root.attrib["viewBox"] == "0 0 48 48" + + +def test_landing_links_to_served_favicon(): + response = app.test_client().get("/") + assert b'href="/favicon.svg?v=2"' in response.data