forked from 00dani/lemoncurry
Switch from django-favicon-plus to django-super-favicon, it performs better and doesn't require a DB table
This commit is contained in:
parent
025910029e
commit
1654ceecf3
6 changed files with 74 additions and 28 deletions
2
Pipfile
2
Pipfile
|
@ -13,7 +13,6 @@ gunicorn = "*"
|
||||||
"psycopg2" = "*"
|
"psycopg2" = "*"
|
||||||
pillow = "*"
|
pillow = "*"
|
||||||
python-memcached = "*"
|
python-memcached = "*"
|
||||||
django-favicon-plus = "*"
|
|
||||||
django-meta = "*"
|
django-meta = "*"
|
||||||
django-redis-cache = "*"
|
django-redis-cache = "*"
|
||||||
django-activeurl = "*"
|
django-activeurl = "*"
|
||||||
|
@ -44,5 +43,6 @@ pytest-django = "*"
|
||||||
python-baseconv = "*"
|
python-baseconv = "*"
|
||||||
django-computed-property = "*"
|
django-computed-property = "*"
|
||||||
docutils = "*"
|
docutils = "*"
|
||||||
|
django-super-favicon = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
22
Pipfile.lock
generated
22
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "4df43e91dcd5baca07940a89c9f23c321de025dd3454739f4266fcbe4490da2d"
|
"sha256": "ff6bfe755c0aaf4328e61d282a464f6bc86731fdd077f04aad1f0ebabacee6d6"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -188,12 +188,6 @@
|
||||||
],
|
],
|
||||||
"version": "==0.8.0"
|
"version": "==0.8.0"
|
||||||
},
|
},
|
||||||
"django-compat": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:3ac9a3bedc56b9365d9eb241bc5157d0c193769bf995f9a78dc1bc24e7c2331b"
|
|
||||||
],
|
|
||||||
"version": "==1.0.15"
|
|
||||||
},
|
|
||||||
"django-compressor": {
|
"django-compressor": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:7732676cfb9d58498dfb522b036f75f3f253f72ea1345ac036434fdc418c2e57",
|
"sha256:7732676cfb9d58498dfb522b036f75f3f253f72ea1345ac036434fdc418c2e57",
|
||||||
|
@ -225,13 +219,6 @@
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==1.9.1"
|
"version": "==1.9.1"
|
||||||
},
|
},
|
||||||
"django-favicon-plus": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:3394a951d8dc611eb1ea027ad1181d7f650ca234506585b27e93d7ed06b981bf"
|
|
||||||
],
|
|
||||||
"index": "pypi",
|
|
||||||
"version": "==0.0.8"
|
|
||||||
},
|
|
||||||
"django-meta": {
|
"django-meta": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:21fc5d0d5fcacda5d038af0babd08afaa4d5bed1b746edb6522c4d3435da8db6",
|
"sha256:21fc5d0d5fcacda5d038af0babd08afaa4d5bed1b746edb6522c4d3435da8db6",
|
||||||
|
@ -287,6 +274,13 @@
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==1.1.0"
|
"version": "==1.1.0"
|
||||||
},
|
},
|
||||||
|
"django-super-favicon": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:56cb5268ea73ef3cbde5cb01fef02fea2ec00739cdae0566d3102009f052f683"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==0.6.1"
|
||||||
|
},
|
||||||
"docutils": {
|
"docutils": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6",
|
"sha256:02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6",
|
||||||
|
|
|
@ -263,3 +263,6 @@ PUSH_HUB = 'https://00dani.superfeedr.com/'
|
||||||
# django-rq
|
# django-rq
|
||||||
# https://github.com/ui/django-rq
|
# https://github.com/ui/django-rq
|
||||||
RQ_QUEUES = {'default': {'USE_REDIS_CACHE': 'default'}}
|
RQ_QUEUES = {'default': {'USE_REDIS_CACHE': 'default'}}
|
||||||
|
|
||||||
|
# django-super-favicon
|
||||||
|
FAVICON_STORAGE = 'django.core.files.storage.DefaultStorage'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load analytical compress favtags lemoncurry_tags meta static theme_colour %}<!doctype html>
|
{% load analytical compress favicon lemoncurry_tags meta static theme_colour %}<!doctype html>
|
||||||
<html dir="ltr" lang="en" class="{% block html_class %}{% endblock %}">
|
<html dir="ltr" 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 %}
|
<head{% meta_namespaces %}>{% site_name as site_name %}{% request_uri request as uri %}{% request_origin request as origin %}
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
<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 %}" />
|
||||||
{% include 'meta/meta.html' %}
|
{% include 'meta/meta.html' %}
|
||||||
{% placeFavicon %}
|
{% get_favicons 'favicon/' %}
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
|
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
|
||||||
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous" />
|
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous" />
|
||||||
|
|
45
wellknowns/favicons.py
Normal file
45
wellknowns/favicons.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
from itertools import chain
|
||||||
|
from django.core.files.storage import default_storage
|
||||||
|
|
||||||
|
|
||||||
|
class Favicon:
|
||||||
|
def __init__(self, size, rel='icon', mime='image/png'):
|
||||||
|
self.rel = rel
|
||||||
|
self.mime = mime
|
||||||
|
if not isinstance(size, tuple):
|
||||||
|
size = (size, size)
|
||||||
|
self.size = size
|
||||||
|
|
||||||
|
@property
|
||||||
|
def url(self):
|
||||||
|
return default_storage.url('favicon/' + self.filename)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def filename(self):
|
||||||
|
return 'favicon-{0}.png'.format(*self.size)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sizes(self):
|
||||||
|
return 'x'.join(str(s) for s in self.size)
|
||||||
|
|
||||||
|
|
||||||
|
tile_sizes = {'small': 128, 'medium': 270, 'wide': (558, 270), 'large': 558}
|
||||||
|
|
||||||
|
|
||||||
|
class Tile(Favicon):
|
||||||
|
def __init__(self, size_name):
|
||||||
|
super().__init__(tile_sizes[size_name])
|
||||||
|
self.size_name = size_name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def filename(self):
|
||||||
|
return '{0}tile.png'.format(self.size_name)
|
||||||
|
|
||||||
|
|
||||||
|
sizes = (32, 57, 76, 96, 120, 128, 144, 180, 195, 228)
|
||||||
|
icons = tuple(chain(
|
||||||
|
(Favicon(s) for s in sizes),
|
||||||
|
(Tile(s) for s in tile_sizes.keys()),
|
||||||
|
(Favicon(152, rel='apple-touch-icon-precomposed'),
|
||||||
|
Favicon(196, rel='shortcut icon'))
|
||||||
|
))
|
|
@ -1,12 +1,16 @@
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from favicon.models import FaviconImg
|
from ..favicons import icons
|
||||||
from lemoncurry import utils
|
from lemoncurry import utils
|
||||||
from lemoncurry.theme import color
|
from lemoncurry.theme import color
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
from textwrap import shorten
|
from textwrap import shorten
|
||||||
|
|
||||||
|
|
||||||
|
def manifest_icons(base):
|
||||||
|
return [{'src': i.url, 'type': i.mime, 'sizes': i.sizes} for i in sorted(icons, key=lambda i: i.size)]
|
||||||
|
|
||||||
|
|
||||||
def manifest(request):
|
def manifest(request):
|
||||||
base = utils.origin(request)
|
base = utils.origin(request)
|
||||||
start_url = reverse('home:index') + '?utm_source=homescreen'
|
start_url = reverse('home:index') + '?utm_source=homescreen'
|
||||||
|
@ -14,6 +18,7 @@ def manifest(request):
|
||||||
app = {
|
app = {
|
||||||
'name': request.site.name,
|
'name': request.site.name,
|
||||||
'short_name': shorten(request.site.name, width=20, placeholder=''),
|
'short_name': shorten(request.site.name, width=20, placeholder=''),
|
||||||
|
'icons': manifest_icons(base),
|
||||||
|
|
||||||
'display': 'browser',
|
'display': 'browser',
|
||||||
'start_url': urljoin(base, start_url),
|
'start_url': urljoin(base, start_url),
|
||||||
|
@ -22,15 +27,14 @@ def manifest(request):
|
||||||
'theme_color': color(2),
|
'theme_color': color(2),
|
||||||
}
|
}
|
||||||
|
|
||||||
rels = ('shortcut icon', 'apple-touch-icon')
|
# icons = FaviconImg.objects.filter(
|
||||||
icons = FaviconImg.objects.filter(
|
# faviconFK__isFavicon=True,
|
||||||
faviconFK__isFavicon=True,
|
# rel__in=rels,
|
||||||
rel__in=rels,
|
# ).order_by('size')
|
||||||
).order_by('size')
|
# app['icons'] = [{
|
||||||
app['icons'] = [{
|
# 'type': 'image/png',
|
||||||
'type': 'image/png',
|
# 'sizes': '{0}x{0}'.format(icon.size),
|
||||||
'sizes': '{0}x{0}'.format(icon.size),
|
# 'src': urljoin(base, icon.faviconImage.url),
|
||||||
'src': urljoin(base, icon.faviconImage.url),
|
# } for icon in icons]
|
||||||
} for icon in icons]
|
|
||||||
|
|
||||||
return JsonResponse(app, content_type='application/manifest+json')
|
return JsonResponse(app, content_type='application/manifest+json')
|
||||||
|
|
Loading…
Reference in a new issue