Use custom storage instead of django-compressor

This commit is contained in:
David Larlet 2024-01-16 17:41:38 -05:00
parent 3e5927f65e
commit 656e29c72b
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
12 changed files with 140 additions and 105 deletions

1
.gitignore vendored
View file

@ -10,6 +10,7 @@ site/*
node_modules
umap.conf
data
static
### Python ###
# Byte-compiled / optimized / DLL files

View file

@ -32,7 +32,6 @@ classifiers = [
dependencies = [
"Django==4.2",
"django-agnocomplete==2.2.0",
"django-compressor==4.3.1",
"django-environ==0.10.0",
"django-probes==1.7.0",
"Pillow==10.0.1",

View file

@ -119,7 +119,6 @@ INSTALLED_APPS = (
"django.contrib.gis",
"django_probes",
"umap",
"compressor",
"social_django",
# See https://github.com/peopledoc/django-agnocomplete/commit/26eda2dfa4a2f8a805ca2ea19a0c504b9d773a1c
# Django does not find the app config in the default place, so the app is not loaded
@ -163,9 +162,16 @@ MEDIA_ROOT = os.path.join("uploads")
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"compressor.finders.CompressorFinder",
]
STATICFILES_DIRS = [] # May be extended when using UMAP_CUSTOM_STATICS
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "umap.utils.UmapManifestStaticFilesStorage",
},
}
# =============================================================================
# Templates
@ -262,9 +268,6 @@ LEAFLET_ZOOM = env.int("LEAFLET_ZOOM", default=6)
# =============================================================================
# Third party app settings
# =============================================================================
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
LOGIN_URL = "login"
SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/login/popup/end/"

View file

@ -29,9 +29,6 @@ DATABASES = {
}
}
COMPRESS_ENABLED = False
COMPRESS_OFFLINE = True
LANGUAGE_CODE = "en"
# Set to False if login into django account should not be possible. You can

View file

@ -1,4 +1,4 @@
{% load compress umap_tags i18n %}
{% load umap_tags i18n static %}
<!DOCTYPE html>
<html {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
@ -17,13 +17,13 @@
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
{# See https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs #}
<link rel="icon"
href="{{ STATIC_URL }}umap/favicons/favicon.ico"
href="{% static 'umap/favicons/favicon.ico' %}"
sizes="32x32">
<link rel="icon"
href="{{ STATIC_URL }}umap/favicons/icon.svg"
href="{% static 'umap/favicons/icon.svg' %}"
type="image/svg+xml">
<link rel="apple-touch-icon"
href="{{ STATIC_URL }}umap/favicons/apple-touch-icon.png">
href="{% static 'umap/favicons/apple-touch-icon.png' %}">
<!-- 180×180 -->
<link rel="manifest" href="/manifest.webmanifest">
</head>

View file

@ -1,9 +1,9 @@
{% load i18n %}
{% load i18n static %}
<div class="wrapper about_summary highlights">
<div class="row">
<div class="col quarter mwide">
<img class="colophon"
src="{{ STATIC_URL }}umap/img/osm.svg"
src="{% static 'umap/img/osm.svg' %}"
alt=""
width="128px"
height="128px" />
@ -13,7 +13,7 @@
</div>
<div class="col umap-features-list half mwide">
<img class="colophon"
src="{{ STATIC_URL }}umap/img/edit.svg"
src="{% static 'umap/img/edit.svg' %}"
alt=""
width="128px"
height="128px" />
@ -29,7 +29,7 @@
</div>
<div class="col quarter mwide">
<img class="colophon"
src="{{ STATIC_URL }}umap/img/opensource.svg"
src="{% static 'umap/img/opensource.svg' %}"
alt=""
width="128px"
height="128px" />

View file

@ -1,12 +1,10 @@
{% extends "base.html" %}
{% load umap_tags compress i18n %}
{% load umap_tags i18n %}
{% block body_class %}
content
{% endblock body_class %}
{% block extra_head %}
{% compress css %}
{% umap_css %}
{% endcompress css %}
{% umap_js %}
{% endblock extra_head %}
{% block header %}

View file

@ -1,28 +1,30 @@
{% load static %}
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/leaflet/leaflet.css" />
href="{% static 'umap/vendors/leaflet/leaflet.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/markercluster/MarkerCluster.css" />
href="{% static 'umap/vendors/markercluster/MarkerCluster.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/markercluster/MarkerCluster.Default.css" />
href="{% static 'umap/vendors/markercluster/MarkerCluster.Default.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/editinosm/Leaflet.EditInOSM.css" />
href="{% static 'umap/vendors/editinosm/Leaflet.EditInOSM.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/minimap/Control.MiniMap.css" />
href="{% static 'umap/vendors/minimap/Control.MiniMap.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/contextmenu/leaflet.contextmenu.css" />
href="{% static 'umap/vendors/contextmenu/leaflet.contextmenu.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/toolbar/leaflet.toolbar.css" />
href="{% static 'umap/vendors/toolbar/leaflet.toolbar.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/measurable/Leaflet.Measurable.css" />
href="{% static 'umap/vendors/measurable/Leaflet.Measurable.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/fullscreen/leaflet.fullscreen.css" />
href="{% static 'umap/vendors/fullscreen/leaflet.fullscreen.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/locatecontrol/L.Control.Locate.css" />
href="{% static 'umap/vendors/locatecontrol/L.Control.Locate.css' %}" />
<link rel="stylesheet"
href="{{ STATIC_URL }}umap/vendors/iconlayers/iconLayers.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}umap/font.css">
<link rel="stylesheet" href="{{ STATIC_URL }}umap/base.css">
<link rel="stylesheet" href="{{ STATIC_URL }}umap/content.css">
<link rel="stylesheet" href="{{ STATIC_URL }}umap/nav.css">
<link rel="stylesheet" href="{{ STATIC_URL }}umap/map.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}umap/theme.css">
href="{% static 'umap/vendors/iconlayers/iconLayers.css' %}" />
<link rel="stylesheet" href="{% static 'umap/font.css' %}">
<link rel="stylesheet" href="{% static 'umap/base.css' %}">
<link rel="stylesheet" href="{% static 'umap/content.css' %}">
<link rel="stylesheet" href="{% static 'umap/nav.css' %}">
<link rel="stylesheet" href="{% static 'umap/map.css' %}" />
<link rel="stylesheet" href="{% static 'umap/theme.css' %}">

View file

@ -1,62 +1,49 @@
{% load compress %}
{% compress js %}
<script type="module" src="{{ STATIC_URL }}umap/js/modules/global.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/editable/Path.Drag.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/editable/Leaflet.Editable.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/hash/leaflet-hash.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/i18n/Leaflet.i18n.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/editinosm/Leaflet.EditInOSM.js"
defer></script>
<script src="{{ STATIC_URL }}umap/vendors/minimap/Control.MiniMap.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/csv2geojson/csv2geojson.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/togeojson/togeojson.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/osmtogeojson/osmtogeojson.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/loading/Control.Loading.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/markercluster/leaflet.markercluster-src.js"
defer></script>
<script src="{{ STATIC_URL }}umap/vendors/contextmenu/leaflet.contextmenu.js"
defer></script>
<script src="{{ STATIC_URL }}umap/vendors/photon/leaflet.photon.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/georsstogeojson/GeoRSSToGeoJSON.js"
defer></script>
<script src="{{ STATIC_URL }}umap/vendors/heat/leaflet-heat.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/fullscreen/Leaflet.fullscreen.js"
defer></script>
<script src="{{ STATIC_URL }}umap/vendors/toolbar/leaflet.toolbar-src.js"
defer></script>
<script src="{{ STATIC_URL }}umap/vendors/formbuilder/Leaflet.FormBuilder.js"
defer></script>
<script src="{{ STATIC_URL }}umap/vendors/measurable/Leaflet.Measurable.js"
defer></script>
<script src="{{ STATIC_URL }}umap/vendors/togpx/togpx.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/iconlayers/iconLayers.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/tokml/tokml.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/locatecontrol/L.Control.Locate.js"
defer></script>
<script src="{{ STATIC_URL }}umap/vendors/dompurify/purify.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/colorbrewer/colorbrewer.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/simple-statistics/simple-statistics.min.js"
defer></script>
{% endcompress %}
{% if locale %}<script src="{{ STATIC_URL }}umap/locale/{{ locale }}.js" defer></script>{% endif %}
{% compress js %}
<script src="{{ STATIC_URL }}umap/js/umap.core.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.autocomplete.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.popup.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.xhr.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.forms.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.icon.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.features.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.permissions.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.datalayer.permissions.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.layer.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.controls.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.slideshow.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.tableeditor.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.browser.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.importer.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.share.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.ui.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/components/fragment.js" defer></script>
{% endcompress %}
{% load static %}
<script type="module" src="{% static 'umap/js/modules/global.js' %}" defer></script>
<script src="{% static 'umap/vendors/editable/Path.Drag.js' %}" defer></script>
<script src="{% static 'umap/vendors/editable/Leaflet.Editable.js' %}" defer></script>
<script src="{% static 'umap/vendors/hash/leaflet-hash.js' %}" defer></script>
<script src="{% static 'umap/vendors/i18n/Leaflet.i18n.js' %}" defer></script>
<script src="{% static 'umap/vendors/editinosm/Leaflet.EditInOSM.js' %}" defer></script>
<script src="{% static 'umap/vendors/minimap/Control.MiniMap.js' %}" defer></script>
<script src="{% static 'umap/vendors/csv2geojson/csv2geojson.js' %}" defer></script>
<script src="{% static 'umap/vendors/togeojson/togeojson.js' %}" defer></script>
<script src="{% static 'umap/vendors/osmtogeojson/osmtogeojson.js' %}" defer></script>
<script src="{% static 'umap/vendors/loading/Control.Loading.js' %}" defer></script>
<script src="{% static 'umap/vendors/markercluster/leaflet.markercluster-src.js' %}" defer></script>
<script src="{% static 'umap/vendors/contextmenu/leaflet.contextmenu.js' %}" defer></script>
<script src="{% static 'umap/vendors/photon/leaflet.photon.js' %}" defer></script>
<script src="{% static 'umap/vendors/georsstogeojson/GeoRSSToGeoJSON.js' %}" defer></script>
<script src="{% static 'umap/vendors/heat/leaflet-heat.js' %}" defer></script>
<script src="{% static 'umap/vendors/fullscreen/Leaflet.fullscreen.js' %}" defer></script>
<script src="{% static 'umap/vendors/toolbar/leaflet.toolbar-src.js' %}" defer></script>
<script src="{% static 'umap/vendors/formbuilder/Leaflet.FormBuilder.js' %}" defer></script>
<script src="{% static 'umap/vendors/measurable/Leaflet.Measurable.js' %}" defer></script>
<script src="{% static 'umap/vendors/togpx/togpx.js' %}" defer></script>
<script src="{% static 'umap/vendors/iconlayers/iconLayers.js' %}" defer></script>
<script src="{% static 'umap/vendors/tokml/tokml.js' %}" defer></script>
<script src="{% static 'umap/vendors/locatecontrol/L.Control.Locate.js' %}" defer></script>
<script src="{% static 'umap/vendors/dompurify/purify.js' %}" defer></script>
<script src="{% static 'umap/vendors/colorbrewer/colorbrewer.js' %}" defer></script>
<script src="{% static 'umap/vendors/simple-statistics/simple-statistics.min.js' %}" defer></script>
{% if locale %}<script src="{% static 'umap/locale/fr.js' %}" defer></script>{% endif %}{# TODO: handle dynamic locale! #}
<script src="{% static 'umap/js/umap.core.js' %}" defer></script>
<script src="{% static 'umap/js/umap.autocomplete.js' %}" defer></script>
<script src="{% static 'umap/js/umap.popup.js' %}" defer></script>
<script src="{% static 'umap/js/umap.xhr.js' %}" defer></script>
<script src="{% static 'umap/js/umap.forms.js' %}" defer></script>
<script src="{% static 'umap/js/umap.icon.js' %}" defer></script>
<script src="{% static 'umap/js/umap.features.js' %}" defer></script>
<script src="{% static 'umap/js/umap.permissions.js' %}" defer></script>
<script src="{% static 'umap/js/umap.datalayer.permissions.js' %}" defer></script>
<script src="{% static 'umap/js/umap.layer.js' %}" defer></script>
<script src="{% static 'umap/js/umap.controls.js' %}" defer></script>
<script src="{% static 'umap/js/umap.slideshow.js' %}" defer></script>
<script src="{% static 'umap/js/umap.tableeditor.js' %}" defer></script>
<script src="{% static 'umap/js/umap.browser.js' %}" defer></script>
<script src="{% static 'umap/js/umap.importer.js' %}" defer></script>
<script src="{% static 'umap/js/umap.share.js' %}" defer></script>
<script src="{% static 'umap/js/umap.js' %}" defer></script>
<script src="{% static 'umap/js/umap.ui.js' %}" defer></script>
<script src="{% static 'umap/js/components/fragment.js' %}" defer></script>

View file

@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load umap_tags compress i18n %}
{% load umap_tags i18n %}
{% block head_title %}
{{ map.name }} - {{ SITE_NAME }}
{% endblock head_title %}
@ -7,9 +7,7 @@
map_detail
{% endblock body_class %}
{% block extra_head %}
{% compress css %}
{% umap_css %}
{% endcompress %}
{% umap_js locale=locale %}
{% if object.share_status != object.PUBLIC %}<meta name="robots" content="noindex">{% endif %}
{% endblock extra_head %}

View file

@ -3,7 +3,6 @@ import os
from umap.settings.base import * # pylint: disable=W0614,W0401
SECRET_KEY = "justfortests"
COMPRESS_ENABLED = False
FROM_EMAIL = "test@test.org"
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"

View file

@ -2,6 +2,7 @@ import gzip
import os
from django.conf import settings
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
from django.urls import URLPattern, URLResolver, get_resolver
@ -162,3 +163,53 @@ def merge_features(reference: list, latest: list, incoming: list):
merged.append(item)
return merged
class UmapManifestStaticFilesStorage(ManifestStaticFilesStorage):
support_js_module_import_aggregation = True
# We remove `;` at the end of all regexps to match our prettier config.
_js_module_import_aggregation_patterns = (
"*.js",
(
(
(
r"""(?P<matched>import(?s:(?P<import>[\s\{].*?))"""
r"""\s*from\s*['"](?P<url>[\.\/].*?)["']\s*)"""
),
'import%(import)s from "%(url)s"\n',
),
(
(
r"""(?P<matched>export(?s:(?P<exports>[\s\{].*?))"""
r"""\s*from\s*["'](?P<url>[\.\/].*?)["']\s*)"""
),
'export%(exports)s from "%(url)s"\n',
),
(
r"""(?P<matched>import\s*['"](?P<url>[\.\/].*?)["']\s*)""",
'import"%(url)s"\n',
),
(
r"""(?P<matched>import\(["'](?P<url>.*?)["']\))""",
"""import("%(url)s")""",
),
),
)
# https://github.com/django/django/blob/0fcee1676c7f14bb08e2cc662898dee56d9cf207↩
# /django/contrib/staticfiles/storage.py#L78C5-L105C6
patterns = (
(
"*.css",
(
r"""(?P<matched>url\(['"]{0,1}\s*(?P<url>.*?)["']{0,1}\))""",
(
r"""(?P<matched>@import\s*["']\s*(?P<url>.*?)["'])""",
"""@import url("%(url)s")""",
),
# Remove CSS source map rewriting
),
),
# Remove JS source map rewriting
)