lemoncurry/wellknowns/views/manifest.py

32 lines
893 B
Python
Raw Permalink Normal View History

from django.http import JsonResponse
from django.urls import reverse
from ..favicons import icons
from lemoncurry import utils
from lemoncurry.theme import color
from urllib.parse import urljoin
from textwrap import shorten
def manifest_icons(base):
2023-08-10 02:52:37 -04:00
return [
{"src": i.url, "type": i.mime, "sizes": i.sizes}
for i in sorted(icons, key=lambda i: i.size)
]
def manifest(request):
base = utils.origin(request)
2023-08-10 02:52:37 -04:00
start_url = reverse("home:index") + "?utm_source=homescreen"
app = {
2023-08-10 02:52:37 -04:00
"name": request.site.name,
"short_name": shorten(request.site.name, width=20, placeholder=""),
"icons": manifest_icons(base),
"display": "browser",
"start_url": urljoin(base, start_url),
"background_color": color(0),
"theme_color": color(3),
}
2023-08-10 02:52:37 -04:00
return JsonResponse(app, content_type="application/manifest+json")