Update manifest.json with extra properties, set theme colour properly as a <meta> as well

This commit is contained in:
Danielle McLean 2017-10-28 15:05:54 +11:00
parent b172d9f139
commit 7429d43280
Signed by: 00dani
GPG Key ID: 5A5D2D1AFF12EEC5
4 changed files with 33 additions and 8 deletions

View File

@ -1,4 +1,4 @@
{% load compress favtags lemoncurry_tags meta static %}<!doctype html>
{% load compress favtags lemoncurry_tags meta static theme_colour %}<!doctype html>
<html lang="en" class="{% block html_class %}{% endblock %}">
<head{% meta_namespaces %}>{% site_name as site_name %}{% request_uri request as uri %}{% request_origin request as origin %}
<base href="{{ origin }}" />
@ -9,7 +9,9 @@
<link rel="hub" href="{% get_push_hub %}" />
<link rel="self" href="{{ uri }}" />
<link rel="manifest" href="{% url 'wellknowns:manifest' %}" />
<meta name="theme-color" content="{% theme_colour 2 %}" />
<meta property="og:url" content="{{ uri }}" />
<meta property="og:title" content="{% firstof title site_name %}" />

View File

@ -0,0 +1,9 @@
from django import template
from ..theme import color
register = template.Library()
@register.simple_tag
def theme_colour(i):
return color(i)

View File

@ -9,3 +9,7 @@ path = join(
)
with open(path, 'r') as f:
theme = safe_load(f)
def color(i):
return '#' + theme['base0' + format(i, '1X')]

View File

@ -1,17 +1,27 @@
from django.conf import settings
from django.http import JsonResponse
from django.urls import reverse
from favicon.models import FaviconImg
from lemoncurry import utils
from lemoncurry.theme import theme
from lemoncurry.theme import color
from urllib.parse import urljoin
from textwrap import shorten
def manifest(request):
origin = utils.origin(request)
base = utils.origin(request)
name = settings.LEMONCURRY_SITE_NAME
start_url = reverse('home:index') + '?utm_source=homescreen'
app = {
'name': settings.LEMONCURRY_SITE_NAME,
'background_color': '#' + theme['base00'],
'theme_color': '#' + theme['base02'],
'name': name,
'short_name': shorten(name, width=20, placeholder=''),
'display': 'browser',
'start_url': urljoin(base, start_url),
'background_color': color(0),
'theme_color': color(2),
}
rels = ('shortcut icon', 'apple-touch-icon')
@ -21,8 +31,8 @@ def manifest(request):
).order_by('size')
app['icons'] = [{
'type': 'image/png',
'size': '{0}x{0}'.format(icon.size),
'src': urljoin(origin, icon.faviconImage.url),
'sizes': '{0}x{0}'.format(icon.size),
'src': urljoin(base, icon.faviconImage.url),
} for icon in icons]
return JsonResponse(app, content_type='application/manifest+json')