Split monolithic index.html and style.css for maintainability

- Extract 15 modals and 3 partials from index.html into Jinja2 templates
  (templates/modals/*.html, templates/partials/*.html)
- Split style.css (3,712 lines) into 11 feature-scoped CSS files under
  static/css/ (base, layout, components, cards, modal, calibration,
  dashboard, streams, patterns, profiles, tutorials)
- Switch root route from FileResponse to Jinja2Templates
- Add jinja2 dependency
- Consolidate duplicate @keyframes spin definition
- Browser receives identical assembled HTML — zero JS changes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-20 00:42:50 +03:00
parent 755077607a
commit 2b90fafb9c
35 changed files with 4986 additions and 4990 deletions

View File

@@ -6,8 +6,10 @@ from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, FileResponse
from fastapi.responses import JSONResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from starlette.requests import Request
from wled_controller import __version__
from wled_controller.api import router
@@ -262,6 +264,10 @@ if static_path.exists():
else:
logger.warning(f"Static files directory not found: {static_path}")
# Jinja2 templates
templates_path = Path(__file__).parent / "templates"
templates = Jinja2Templates(directory=str(templates_path))
@app.exception_handler(Exception)
async def global_exception_handler(request, exc):
@@ -279,20 +285,9 @@ async def global_exception_handler(request, exc):
@app.get("/")
async def root():
async def root(request: Request):
"""Serve the web UI dashboard."""
static_path = Path(__file__).parent / "static" / "index.html"
if static_path.exists():
return FileResponse(static_path)
# Fallback to JSON if static files not found
return {
"name": "LED Grab",
"version": __version__,
"docs": "/docs",
"health": "/health",
"api": "/api/v1",
}
return templates.TemplateResponse(request, "index.html")
if __name__ == "__main__":