Browse Source

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

pull/1/head
Danielle McLean 5 years ago
parent
commit
55731c63ce
Signed by: 00dani
GPG Key ID: 5A5D2D1AFF12EEC5
  1. 1
      Pipfile
  2. 21
      Pipfile.lock
  3. 1
      lemoncurry/templates/lemoncurry/layout.html
  4. 11
      lemoncurry/theme.py
  5. 1
      wellknowns/urls.py
  6. 1
      wellknowns/views/__init__.py
  7. 28
      wellknowns/views/manifest.py

1
Pipfile

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

21
Pipfile.lock generated

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "bf80c6036fc124e9afa1aa029b73d614b477dba02cf948696dd8eb1fa50dc745"
"sha256": "dc4aa7d01f78e031ce0e169c70b3056b8a436bfc3195126b6a801943ee39e2fb"
},
"host-environment-markers": {
"implementation_name": "cpython",
@ -344,6 +344,25 @@
],
"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": {
"hashes": [
"sha256:60222a612b83231ed99e6cb36e55311227c395d0d0f62e41bb51ebbb84a9a22b",

1
lemoncurry/templates/lemoncurry/layout.html

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

11
lemoncurry/theme.py

@ -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)

1
wellknowns/urls.py

@ -7,5 +7,6 @@ urlpatterns = [
url(r'^keybase.txt$', views.keybase, name='keybase'),
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'^manifest.json$', views.manifest, name='manifest'),
url(r'^webfinger$', views.webfinger, name='webfinger'),
]

1
wellknowns/views/__init__.py

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

28
wellknowns/views/manifest.py

@ -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')
Loading…
Cancel
Save