feat(easel): add widget mode support

This commit is contained in:
2026-06-12 00:39:54 +03:00
parent f368e6717c
commit ce31413400
2 changed files with 12 additions and 10 deletions

View File

@@ -19,9 +19,11 @@
{% endblock %} {% endblock %}
</head> </head>
<body> <body class="{{ request | is_widget and 'widget' or ''}}">
<div class="app col-lg-8 mx-auto p-3 py-md-5"> <div class="app col-lg-8 mx-auto p-3 py-md-5">
{% if not request | is_widget %}
<header class="app-header pb-3 mb-5 border-bottom"> <header class="app-header pb-3 mb-5 border-bottom">
<div>{{request.query_params.widget}}</div>
<div class="link-list"> <div class="link-list">
<app-link href="/" <app-link href="/"
icon="gear">API Gallery</app-link> icon="gear">API Gallery</app-link>
@@ -105,22 +107,16 @@
</li> </li>
</ul> </ul>
</header> </header>
{% endif %}
<main> <main>
{% block content %}{% endblock %} {% block content %}{% endblock %}
</main> </main>
{% if not request | is_widget %}
<footer class="pt-5 my-5 text-muted border-top"> <footer class="pt-5 my-5 text-muted border-top">
Created by shmyga &middot; &copy; 2026 Created by shmyga &middot; &copy; 2026
</footer> </footer>
{% endif %}
</div> </div>
{# <script>
(function () {
const params = new URLSearchParams(window.location.search);
const widget = params.get('widget') || window.location.hostname.startsWith('weather');
if (widget) {
document.body.classList.add('widget');
}
}());
</script> #}
</body> </body>
</html> </html>

View File

@@ -1,6 +1,7 @@
from pathlib import Path from pathlib import Path
from babel.dates import format_date from babel.dates import format_date
from fastapi import Request
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from gallery.version import __version__ from gallery.version import __version__
@@ -8,6 +9,10 @@ from gallery.version import __version__
from ...translation import _ from ...translation import _
def is_widget(request: Request) -> bool:
return request.url.hostname.startswith("weather") or (request.query_params.get("widget") is not None)
def build_templates(templates_dir: Path | None = None, filters: dict | None = None) -> Jinja2Templates: def build_templates(templates_dir: Path | None = None, filters: dict | None = None) -> Jinja2Templates:
directory = [Path(__file__).parent.parent / "templates"] directory = [Path(__file__).parent.parent / "templates"]
if templates_dir: if templates_dir:
@@ -20,6 +25,7 @@ def build_templates(templates_dir: Path | None = None, filters: dict | None = No
"format_date": format_date, "format_date": format_date,
} }
) )
templates.env.filters["is_widget"] = is_widget
if filters: if filters:
templates.env.filters.update(filters) templates.env.filters.update(filters)
return templates return templates