feat(easel): add widget mode support
This commit is contained in:
@@ -19,9 +19,11 @@
|
||||
{% endblock %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body class="{{ request | is_widget and 'widget' or ''}}">
|
||||
<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">
|
||||
<div>{{request.query_params.widget}}</div>
|
||||
<div class="link-list">
|
||||
<app-link href="/"
|
||||
icon="gear">API Gallery</app-link>
|
||||
@@ -105,22 +107,16 @@
|
||||
</li>
|
||||
</ul>
|
||||
</header>
|
||||
{% endif %}
|
||||
<main>
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
{% if not request | is_widget %}
|
||||
<footer class="pt-5 my-5 text-muted border-top">
|
||||
Created by shmyga · © 2026
|
||||
</footer>
|
||||
{% endif %}
|
||||
</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>
|
||||
|
||||
</html>
|
||||
@@ -1,6 +1,7 @@
|
||||
from pathlib import Path
|
||||
|
||||
from babel.dates import format_date
|
||||
from fastapi import Request
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from gallery.version import __version__
|
||||
@@ -8,6 +9,10 @@ from gallery.version import __version__
|
||||
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:
|
||||
directory = [Path(__file__).parent.parent / "templates"]
|
||||
if templates_dir:
|
||||
@@ -20,6 +25,7 @@ def build_templates(templates_dir: Path | None = None, filters: dict | None = No
|
||||
"format_date": format_date,
|
||||
}
|
||||
)
|
||||
templates.env.filters["is_widget"] = is_widget
|
||||
if filters:
|
||||
templates.env.filters.update(filters)
|
||||
return templates
|
||||
|
||||
Reference in New Issue
Block a user