diff --git a/umap/static/favicon.ico b/umap/static/favicon.ico deleted file mode 100644 index 0aa459cc..00000000 Binary files a/umap/static/favicon.ico and /dev/null differ diff --git a/umap/static/umap/favicons/apple-touch-icon.png b/umap/static/umap/favicons/apple-touch-icon.png index 6bace25e..0f2ff064 100644 Binary files a/umap/static/umap/favicons/apple-touch-icon.png and b/umap/static/umap/favicons/apple-touch-icon.png differ diff --git a/umap/static/umap/favicons/favicon.ico b/umap/static/umap/favicons/favicon.ico index 4deae7d7..39affe5c 100644 Binary files a/umap/static/umap/favicons/favicon.ico and b/umap/static/umap/favicons/favicon.ico differ diff --git a/umap/static/umap/favicons/icon-192.png b/umap/static/umap/favicons/icon-192.png index d46f0a3b..5a4175dd 100644 Binary files a/umap/static/umap/favicons/icon-192.png and b/umap/static/umap/favicons/icon-192.png differ diff --git a/umap/static/umap/favicons/icon-512.png b/umap/static/umap/favicons/icon-512.png index 5e44c836..3103a0c2 100644 Binary files a/umap/static/umap/favicons/icon-512.png and b/umap/static/umap/favicons/icon-512.png differ diff --git a/umap/static/umap/favicons/icon.svg b/umap/static/umap/favicons/icon.svg index 9bb4774a..f7fbf130 100644 --- a/umap/static/umap/favicons/icon.svg +++ b/umap/static/umap/favicons/icon.svg @@ -1,5 +1,5 @@ - - - - + + + + diff --git a/umap/templates/base.html b/umap/templates/base.html index 9e5a8d34..0a57fe35 100644 --- a/umap/templates/base.html +++ b/umap/templates/base.html @@ -16,9 +16,9 @@ {# See https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs #} - - - + + + diff --git a/umap/urls.py b/umap/urls.py index 6f52c00f..cd32d406 100644 --- a/umap/urls.py +++ b/umap/urls.py @@ -5,9 +5,11 @@ from django.conf.urls.static import static from django.contrib import admin from django.contrib.auth import views as auth_views from django.contrib.auth.decorators import login_required +from django.contrib.staticfiles.storage import staticfiles_storage from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.views.decorators.cache import cache_control, cache_page, never_cache from django.views.decorators.csrf import ensure_csrf_cookie +from django.views.generic.base import RedirectView from . import views from .decorators import ( @@ -185,12 +187,20 @@ urlpatterns += i18n_patterns( ) urlpatterns += ( path("stats/", cache_page(60 * 60)(views.stats), name="stats"), - path("favicon.ico", views.favicon_file), - path("icon.svg", views.favicon_file), - path("apple-touch-icon.png", views.favicon_file), - path("manifest.webmanifest", views.favicon_file), - path("icon-192.png", views.favicon_file), - path("icon-512.png", views.favicon_file), + path( + "favicon.ico", + cache_control(max_age=60 * 60 * 24, immutable=True, public=True)( + RedirectView.as_view( + url=staticfiles_storage.url("umap/favicons/favicon.ico") + ) + ), + ), + path( + "manifest.webmanifest", + cache_control(max_age=60 * 60 * 24, immutable=True, public=True)( + views.webmanifest + ), + ), ) if settings.DEBUG and settings.MEDIA_ROOT: diff --git a/umap/views.py b/umap/views.py index fc885589..d9f8d647 100644 --- a/umap/views.py +++ b/umap/views.py @@ -15,13 +15,13 @@ from django.contrib.auth import logout as do_logout from django.contrib.auth import get_user_model from django.contrib.gis.measure import D from django.contrib.postgres.search import SearchQuery, SearchVector +from django.contrib.staticfiles.storage import staticfiles_storage from django.core.mail import send_mail from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.core.signing import BadSignature, Signer from django.core.validators import URLValidator, ValidationError from django.db.models import Q from django.http import ( - FileResponse, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, @@ -1018,14 +1018,24 @@ def stats(request): @require_GET -@cache_control(max_age=60 * 60 * 24, immutable=True, public=True) # one day -def favicon_file(request): - # See https://adamj.eu/tech/2022/01/18/how-to-add-a-favicon-to-your-django-site/ - name = request.path.lstrip("/") - file = (Path(settings.PROJECT_DIR) / "static" / "umap" / "favicons" / name).open( - "rb" +@cache_control(max_age=60 * 60 * 24, immutable=True, public=True) # One day. +def webmanifest(request): + return simple_json_response( + **{ + "icons": [ + { + "src": staticfiles_storage.url("umap/favicons/icon-192.png"), + "type": "image/png", + "sizes": "192x192", + }, + { + "src": staticfiles_storage.url("umap/favicons/icon-512.png"), + "type": "image/png", + "sizes": "512x512", + }, + ] + } ) - return FileResponse(file) def logout(request):