2017-10-27 23:29:07 -04:00
|
|
|
from django.http import JsonResponse
|
2017-10-28 00:05:54 -04:00
|
|
|
from django.urls import reverse
|
2018-04-19 22:35:51 -04:00
|
|
|
from ..favicons import icons
|
2017-10-27 23:29:07 -04:00
|
|
|
from lemoncurry import utils
|
2017-10-28 00:05:54 -04:00
|
|
|
from lemoncurry.theme import color
|
2017-10-27 23:29:07 -04:00
|
|
|
from urllib.parse import urljoin
|
2017-10-28 00:05:54 -04:00
|
|
|
from textwrap import shorten
|
2017-10-27 23:29:07 -04:00
|
|
|
|
|
|
|
|
2018-04-19 22:35:51 -04:00
|
|
|
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)
|
|
|
|
]
|
2018-04-19 22:35:51 -04:00
|
|
|
|
|
|
|
|
2017-10-27 23:29:07 -04:00
|
|
|
def manifest(request):
|
2017-10-28 00:05:54 -04:00
|
|
|
base = utils.origin(request)
|
2023-08-10 02:52:37 -04:00
|
|
|
start_url = reverse("home:index") + "?utm_source=homescreen"
|
2017-10-28 00:05:54 -04:00
|
|
|
|
2017-10-27 23:29:07 -04:00
|
|
|
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),
|
2017-10-27 23:29:07 -04:00
|
|
|
}
|
|
|
|
|
2023-08-10 02:52:37 -04:00
|
|
|
return JsonResponse(app, content_type="application/manifest+json")
|