style: format code
This commit is contained in:
@@ -3,11 +3,8 @@ from typing import NamedTuple
|
||||
|
||||
from fastapi import APIRouter, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from gallery.version import __version__
|
||||
|
||||
from ..translation import _
|
||||
from ..common.utils.template import build_templates
|
||||
|
||||
|
||||
class Section(NamedTuple):
|
||||
@@ -25,8 +22,7 @@ base_dir = Path(__file__).parent
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
templates = Jinja2Templates(directory=base_dir / "templates")
|
||||
templates.env.globals.update({"_": _})
|
||||
templates = build_templates()
|
||||
|
||||
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
@@ -35,7 +31,6 @@ async def get_section_list(request: Request):
|
||||
request=request,
|
||||
name="root_index.html",
|
||||
context={
|
||||
"version": __version__,
|
||||
"sections": SECTIONS,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
Created by shmyga · © 2026
|
||||
</footer>
|
||||
</div>
|
||||
<script>
|
||||
{# <script>
|
||||
(function () {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const widget = params.get('widget') || window.location.hostname.startsWith('weather');
|
||||
@@ -120,7 +120,7 @@
|
||||
document.body.classList.add('widget');
|
||||
}
|
||||
}());
|
||||
</script>
|
||||
</script> #}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
0
gallery/easel/route/view/common/utils/__init__.py
Normal file
0
gallery/easel/route/view/common/utils/__init__.py
Normal file
25
gallery/easel/route/view/common/utils/template.py
Normal file
25
gallery/easel/route/view/common/utils/template.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from pathlib import Path
|
||||
|
||||
from babel.dates import format_date
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from gallery.version import __version__
|
||||
|
||||
from ...translation import _
|
||||
|
||||
|
||||
def build_templates(templates_dir: Path | None = None, filters: dict | None = None) -> Jinja2Templates:
|
||||
directory = [Path(__file__).parent.parent / "templates"]
|
||||
if templates_dir:
|
||||
directory.append(templates_dir)
|
||||
templates = Jinja2Templates(directory=directory)
|
||||
templates.env.globals.update(
|
||||
{
|
||||
"_": _,
|
||||
"version": __version__,
|
||||
"format_date": format_date,
|
||||
}
|
||||
)
|
||||
if filters:
|
||||
templates.env.filters.update(filters)
|
||||
return templates
|
||||
Reference in New Issue
Block a user