Add support for generating a simple Web App Manifest file, which helps mobile browsers display the site smartly

This commit is contained in:
Danielle McLean 2017-10-28 14:29:07 +11:00
parent 5987e54105
commit 55731c63ce
Signed by untrusted user: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
7 changed files with 63 additions and 1 deletions

View file

@ -27,6 +27,7 @@ bleach = "*"
django-debug-toolbar = "*" django-debug-toolbar = "*"
xrd = "*" xrd = "*"
django-push = "*" django-push = "*"
pyyaml = "*"
[dev-packages] [dev-packages]

21
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "bf80c6036fc124e9afa1aa029b73d614b477dba02cf948696dd8eb1fa50dc745" "sha256": "dc4aa7d01f78e031ce0e169c70b3056b8a436bfc3195126b6a801943ee39e2fb"
}, },
"host-environment-markers": { "host-environment-markers": {
"implementation_name": "cpython", "implementation_name": "cpython",
@ -344,6 +344,25 @@
], ],
"version": "==2017.2" "version": "==2017.2"
}, },
"pyyaml": {
"hashes": [
"sha256:3262c96a1ca437e7e4763e2843746588a965426550f3797a79fca9c6199c431f",
"sha256:16b20e970597e051997d90dc2cddc713a2876c47e3d92d59ee198700c5427736",
"sha256:e863072cdf4c72eebf179342c94e6989c67185842d9997960b3e69290b2fa269",
"sha256:bc6bced57f826ca7cb5125a10b23fd0f2fff3b7c4701d64c439a300ce665fff8",
"sha256:c01b880ec30b5a6e6aa67b09a2fe3fb30473008c85cd6a67359a1b15ed6d83a4",
"sha256:827dc04b8fa7d07c44de11fabbc888e627fa8293b695e0f99cb544fdfa1bf0d1",
"sha256:592766c6303207a20efc445587778322d7f73b161bd994f227adaa341ba212ab",
"sha256:5f84523c076ad14ff5e6c037fe1c89a7f73a3e04cf0377cb4d017014976433f3",
"sha256:0c507b7f74b3d2dd4d1322ec8a94794927305ab4cebbe89cc47fe5e81541e6e8",
"sha256:b4c423ab23291d3945ac61346feeb9a0dc4184999ede5e7c43e1ffb975130ae6",
"sha256:ca233c64c6e40eaa6c66ef97058cdc80e8d0157a443655baa1b2966e812807ca",
"sha256:4474f8ea030b5127225b8894d626bb66c01cda098d47a2b0d3429b6700af9fd8",
"sha256:326420cbb492172dec84b0f65c80942de6cedb5233c413dd824483989c000608",
"sha256:5ac82e411044fb129bae5cfbeb3ba626acb2af31a8d17d175004b70862a741a7"
],
"version": "==3.12"
},
"qrcode": { "qrcode": {
"hashes": [ "hashes": [
"sha256:60222a612b83231ed99e6cb36e55311227c395d0d0f62e41bb51ebbb84a9a22b", "sha256:60222a612b83231ed99e6cb36e55311227c395d0d0f62e41bb51ebbb84a9a22b",

View file

@ -9,6 +9,7 @@
<link rel="hub" href="{% get_push_hub %}" /> <link rel="hub" href="{% get_push_hub %}" />
<link rel="self" href="{{ uri }}" /> <link rel="self" href="{{ uri }}" />
<link rel="manifest" href="{% url 'wellknowns:manifest' %}" />
<meta property="og:url" content="{{ uri }}" /> <meta property="og:url" content="{{ uri }}" />
<meta property="og:title" content="{% firstof title site_name %}" /> <meta property="og:title" content="{% firstof title site_name %}" />

11
lemoncurry/theme.py Normal file
View file

@ -0,0 +1,11 @@
from django.conf import settings
from os.path import join
from yaml import safe_load
path = join(
settings.BASE_DIR,
'lemoncurry', 'static',
'base16-materialtheme-scheme', 'material-darker.yaml',
)
with open(path, 'r') as f:
theme = safe_load(f)

View file

@ -7,5 +7,6 @@ urlpatterns = [
url(r'^keybase.txt$', views.keybase, name='keybase'), url(r'^keybase.txt$', views.keybase, name='keybase'),
url(r'^host-meta$', views.host_meta_xml, name='host-meta'), url(r'^host-meta$', views.host_meta_xml, name='host-meta'),
url(r'^host-meta.json$', views.host_meta_json, name='host-meta.json'), url(r'^host-meta.json$', views.host_meta_json, name='host-meta.json'),
url(r'^manifest.json$', views.manifest, name='manifest'),
url(r'^webfinger$', views.webfinger, name='webfinger'), url(r'^webfinger$', views.webfinger, name='webfinger'),
] ]

View file

@ -1,3 +1,4 @@
from .static import keybase from .static import keybase
from .host_meta import host_meta_xml, host_meta_json from .host_meta import host_meta_xml, host_meta_json
from .manifest import manifest
from .webfinger import webfinger from .webfinger import webfinger

View file

@ -0,0 +1,28 @@
from django.conf import settings
from django.http import JsonResponse
from favicon.models import FaviconImg
from lemoncurry import utils
from lemoncurry.theme import theme
from urllib.parse import urljoin
def manifest(request):
origin = utils.origin(request)
app = {
'name': settings.LEMONCURRY_SITE_NAME,
'background_color': '#' + theme['base00'],
'theme_color': '#' + theme['base02'],
}
rels = ('shortcut icon', 'apple-touch-icon')
icons = FaviconImg.objects.filter(
faviconFK__isFavicon=True,
rel__in=rels,
).order_by('size')
app['icons'] = [{
'type': 'image/png',
'size': '{0}x{0}'.format(icon.size),
'src': urljoin(origin, icon.faviconImage.url),
} for icon in icons]
return JsonResponse(app, content_type='application/manifest+json')