a Django-based indieweb.org site https://00dani.me/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2KB

  1. from django.http import JsonResponse
  2. from django.urls import reverse
  3. from ..favicons import icons
  4. from lemoncurry import utils
  5. from lemoncurry.theme import color
  6. from urllib.parse import urljoin
  7. from textwrap import shorten
  8. def manifest_icons(base):
  9. return [{'src': i.url, 'type': i.mime, 'sizes': i.sizes} for i in sorted(icons, key=lambda i: i.size)]
  10. def manifest(request):
  11. base = utils.origin(request)
  12. start_url = reverse('home:index') + '?utm_source=homescreen'
  13. app = {
  14. 'name': request.site.name,
  15. 'short_name': shorten(request.site.name, width=20, placeholder=''),
  16. 'icons': manifest_icons(base),
  17. 'display': 'browser',
  18. 'start_url': urljoin(base, start_url),
  19. 'background_color': color(0),
  20. 'theme_color': color(2),
  21. }
  22. # icons = FaviconImg.objects.filter(
  23. # faviconFK__isFavicon=True,
  24. # rel__in=rels,
  25. # ).order_by('size')
  26. # app['icons'] = [{
  27. # 'type': 'image/png',
  28. # 'sizes': '{0}x{0}'.format(icon.size),
  29. # 'src': urljoin(base, icon.faviconImage.url),
  30. # } for icon in icons]
  31. return JsonResponse(app, content_type='application/manifest+json')