From 5e2add90a89b62fd86be619e8a7a8f406f562a2f Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sun, 2 Jun 2024 19:47:35 +0200 Subject: [PATCH] Minify CSS and JavaScript files Signed-off-by: Emmy D'Anello --- Dockerfile | 4 +- chat/static/{ => tfjm}/chat.webmanifest | 6 +- chat/static/{ => tfjm/js}/chat.js | 0 chat/templates/chat/chat.html | 5 +- chat/templates/chat/fullscreen.html | 16 ++-- chat/templates/chat/login.html | 12 ++- draw/static/{ => tfjm/js}/draw.js | 0 draw/templates/draw/index.html | 3 +- .../participation/upload_synthesis.html | 8 +- .../registration/upload_health_sheet.html | 2 +- requirements.txt | 5 +- tfjm/settings.py | 79 ++++++++++++++++-- tfjm/static/{ => tfjm}/Fiche_sanitaire.pdf | Bin tfjm/static/{ => tfjm}/Fiche_synthèse.docx | Bin tfjm/static/{ => tfjm}/Fiche_synthèse.odt | Bin tfjm/static/{ => tfjm}/Fiche_synthèse.pdf | Bin tfjm/static/{ => tfjm}/Fiche_synthèse.tex | 0 tfjm/static/{ => tfjm/img}/logo.png | Bin tfjm/static/{ => tfjm/img}/logo_animath.png | Bin tfjm/static/{ => tfjm/img}/logo_animath.svg | 0 tfjm/static/{ => tfjm/img}/tfjm-192.png | Bin tfjm/static/{ => tfjm/img}/tfjm-512.png | Bin tfjm/static/{ => tfjm/img}/tfjm-square.svg | 0 tfjm/static/{ => tfjm/img}/tfjm.svg | 0 tfjm/static/{ => tfjm/js}/main.js | 0 tfjm/static/{ => tfjm/js}/theme.js | 0 tfjm/templates/base.html | 20 ++--- tfjm/templates/navbar.html | 2 +- tox.ini | 2 +- 29 files changed, 113 insertions(+), 51 deletions(-) rename chat/static/{ => tfjm}/chat.webmanifest (79%) rename chat/static/{ => tfjm/js}/chat.js (100%) rename draw/static/{ => tfjm/js}/draw.js (100%) rename tfjm/static/{ => tfjm}/Fiche_sanitaire.pdf (100%) rename tfjm/static/{ => tfjm}/Fiche_synthèse.docx (100%) rename tfjm/static/{ => tfjm}/Fiche_synthèse.odt (100%) rename tfjm/static/{ => tfjm}/Fiche_synthèse.pdf (100%) rename tfjm/static/{ => tfjm}/Fiche_synthèse.tex (100%) rename tfjm/static/{ => tfjm/img}/logo.png (100%) rename tfjm/static/{ => tfjm/img}/logo_animath.png (100%) rename tfjm/static/{ => tfjm/img}/logo_animath.svg (100%) rename tfjm/static/{ => tfjm/img}/tfjm-192.png (100%) rename tfjm/static/{ => tfjm/img}/tfjm-512.png (100%) rename tfjm/static/{ => tfjm/img}/tfjm-square.svg (100%) rename tfjm/static/{ => tfjm/img}/tfjm.svg (100%) rename tfjm/static/{ => tfjm/js}/main.js (100%) rename tfjm/static/{ => tfjm/js}/theme.js (100%) diff --git a/Dockerfile b/Dockerfile index b00506d..d8e9ec4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,12 @@ FROM python:3.12-alpine ENV PYTHONUNBUFFERED 1 ENV DJANGO_ALLOW_ASYNC_UNSAFE 1 -RUN apk add --no-cache gettext nginx gcc git libc-dev libffi-dev libxml2-dev libxslt-dev postgresql-dev libmagic texlive texmf-dist-latexextra +RUN apk add --no-cache gettext nginx gcc git libc-dev libffi-dev libxml2-dev libxslt-dev npm postgresql-dev libmagic texlive texmf-dist-latexextra RUN apk add --no-cache bash +RUN npm install -g yuglify + RUN mkdir /code /code/docs WORKDIR /code COPY requirements.txt /code/requirements.txt diff --git a/chat/static/chat.webmanifest b/chat/static/tfjm/chat.webmanifest similarity index 79% rename from chat/static/chat.webmanifest rename to chat/static/tfjm/chat.webmanifest index 156d0a1..109e19f 100644 --- a/chat/static/chat.webmanifest +++ b/chat/static/tfjm/chat.webmanifest @@ -4,19 +4,19 @@ "display": "standalone", "icons": [ { - "src": "tfjm-square.svg", + "src": "/static/tfjm/img/tfjm-square.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "maskable" }, { - "src": "tfjm-512.png", + "src": "/static/tfjm/img/tfjm-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }, { - "src": "tfjm-192.png", + "src": "/static/tfjm/img/tfjm-192.png", "sizes": "192x192", "type": "image/png", "purpose": "maskable" diff --git a/chat/static/chat.js b/chat/static/tfjm/js/chat.js similarity index 100% rename from chat/static/chat.js rename to chat/static/tfjm/js/chat.js diff --git a/chat/templates/chat/chat.html b/chat/templates/chat/chat.html index f214d3a..5588aab 100644 --- a/chat/templates/chat/chat.html +++ b/chat/templates/chat/chat.html @@ -2,10 +2,11 @@ {% load static %} {% load i18n %} +{% load pipeline %} {% block extracss %} {# Webmanifest PWA permettant l'installation de l'application sur un écran d'accueil, pour navigateurs supportés #} - + {% endblock %} {% block content-title %}{% endblock %} @@ -16,5 +17,5 @@ {% block extrajavascript %} {# Ce script contient toutes les données pour la gestion du chat. #} - + {% javascript 'chat' %} {% endblock %} diff --git a/chat/templates/chat/fullscreen.html b/chat/templates/chat/fullscreen.html index 1d354c3..20d2f21 100644 --- a/chat/templates/chat/fullscreen.html +++ b/chat/templates/chat/fullscreen.html @@ -1,4 +1,4 @@ -{% load i18n static %} +{% load i18n pipeline static %} {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %} @@ -15,23 +15,21 @@ - {# Bootstrap CSS #} - - - + {# Bootstrap + Font Awesome CSS #} + {% stylesheet 'bootstrap_fontawesome' %} {# Bootstrap JavaScript #} - + {% javascript 'bootstrap' %} {# Webmanifest PWA permettant l'installation de l'application sur un écran d'accueil, pour navigateurs supportés #} - + {% include "chat/content.html" with fullscreen=True %} {# Inclusion du script permettant de gérer le thème sombre et le thème clair #} - +{% javascript 'theme' %} {# Inclusion du script gérant le chat #} - +{% javascript 'chat' %} diff --git a/chat/templates/chat/login.html b/chat/templates/chat/login.html index c5d1f00..a77738b 100644 --- a/chat/templates/chat/login.html +++ b/chat/templates/chat/login.html @@ -1,4 +1,4 @@ -{% load i18n static %} +{% load i18n pipeline static %} {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %} @@ -16,15 +16,13 @@ {# Bootstrap CSS #} - - - + {% stylesheet 'bootstrap_fontawesome' %} {# Bootstrap JavaScript #} - + {% javascript 'bootstrap' %} {# Webmanifest PWA permettant l'installation de l'application sur un écran d'accueil, pour navigateurs supportés #} - +
@@ -33,6 +31,6 @@
{# Inclusion du script permettant de gérer le thème sombre et le thème clair #} - +{% javascript 'theme' %} diff --git a/draw/static/draw.js b/draw/static/tfjm/js/draw.js similarity index 100% rename from draw/static/draw.js rename to draw/static/tfjm/js/draw.js diff --git a/draw/templates/draw/index.html b/draw/templates/draw/index.html index da55800..75de5cb 100644 --- a/draw/templates/draw/index.html +++ b/draw/templates/draw/index.html @@ -2,6 +2,7 @@ {% load static %} {% load i18n %} +{% load pipeline %} {% block content %} {# The navbar to select the tournament #} @@ -40,5 +41,5 @@ {{ problems|length|json_script:'problems_count' }} {# This script contains all data for the draw management #} - + {% javascript 'draw' %} {% endblock %} diff --git a/participation/templates/participation/upload_synthesis.html b/participation/templates/participation/upload_synthesis.html index df7e48d..87415a5 100644 --- a/participation/templates/participation/upload_synthesis.html +++ b/participation/templates/participation/upload_synthesis.html @@ -7,10 +7,10 @@
{% trans "Templates:" %} - PDF — - TEX — - ODT — - DOCX + PDF — + TEX — + ODT — + DOCX
{% csrf_token %} {{ form|crispy }} diff --git a/registration/templates/registration/upload_health_sheet.html b/registration/templates/registration/upload_health_sheet.html index 0c4415b..8b88232 100644 --- a/registration/templates/registration/upload_health_sheet.html +++ b/registration/templates/registration/upload_health_sheet.html @@ -9,7 +9,7 @@
{% trans "Health sheet template:" %} - {% trans "Download" %} + {% trans "Download" %}
{% csrf_token %} {{ form|crispy }} diff --git a/requirements.txt b/requirements.txt index 5b26374..4847d11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,14 +5,15 @@ Django>=5.0.3,<6.0 django-crispy-forms~=2.1 django-extensions~=3.2.3 django-filter~=23.5 -elasticsearch~=7.17.9 -git+https://github.com/django-haystack/django-haystack.git#v3.3b1 +git+https://github.com/django-haystack/django-haystack.git#v3.3b2 django-mailer~=2.3.1 django-phonenumber-field~=7.3.0 +django-pipeline~=3.1.0 django-polymorphic~=3.1.0 django-tables2~=2.7.0 djangorestframework~=3.14.0 django-rest-polymorphic~=0.1.10 +elasticsearch~=7.17.9 gspread~=6.1.0 gunicorn~=21.2.0 odfpy~=1.4.1 diff --git a/tfjm/settings.py b/tfjm/settings.py index 4c6a0e0..0e094fb 100644 --- a/tfjm/settings.py +++ b/tfjm/settings.py @@ -7,10 +7,10 @@ Django settings for tfjm project. Generated by 'django-admin startproject' using Django 3.0.5. For more information on this file, see -https://docs.djangoproject.com/en/3.0/topics/settings/ +https://docs.djangoproject.com/en/5.0/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/3.0/ref/settings/ +https://docs.djangoproject.com/en/5.0/ref/settings/ """ import os @@ -25,7 +25,7 @@ PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) ADMINS = [("Emmy D'Anello", "emmy.danello@animath.fr")] # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'CHANGE_ME_IN_ENV_SETTINGS') @@ -63,6 +63,7 @@ INSTALLED_APPS = [ 'haystack', 'logs', 'phonenumber_field', + 'pipeline', 'polymorphic', 'rest_framework', 'rest_framework.authtoken', @@ -95,6 +96,8 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.sites.middleware.CurrentSiteMiddleware', + 'django.middleware.gzip.GZipMiddleware', + 'pipeline.middleware.MinifyHTMLMiddleware', 'tfjm.middlewares.SessionMiddleware', 'tfjm.middlewares.FetchMiddleware', ] @@ -126,7 +129,7 @@ ASGI_APPLICATION = 'tfjm.asgi.application' WSGI_APPLICATION = 'tfjm.wsgi.application' # Password validation -# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -161,7 +164,7 @@ REST_FRAMEWORK = { } # Internationalization -# https://docs.djangoproject.com/en/3.0/topics/i18n/ +# https://docs.djangoproject.com/en/5.0/topics/i18n/ LANGUAGE_CODE = 'en' @@ -181,7 +184,7 @@ USE_TZ = True LOCALE_PATHS = [os.path.join(BASE_DIR, "locale")] # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/3.0/howto/static-files/ +# https://docs.djangoproject.com/en/5.0/howto/static-files/ STATIC_URL = '/static/' @@ -191,6 +194,70 @@ STATICFILES_DIRS = [ STATIC_ROOT = os.path.join(BASE_DIR, "static") +STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage' + +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'pipeline.finders.PipelineFinder', +) + +PIPELINE = { + 'DISABLE_WRAPPER': True, + 'JAVASCRIPT': { + 'bootstrap': { + 'source_filenames': { + 'bootstrap/js/bootstrap.bundle.min.js', + }, + 'output_filename': 'tfjm/js/bootstrap.bundle.min.js', + }, + 'bootstrap_select': { + 'source_filenames': { + 'jquery/jquery.min.js', + 'bootstrap-select/js/bootstrap-select.min.js', + 'bootstrap-select/js/defaults-fr_FR.min.js', + }, + 'output_filename': 'tfjm/js/bootstrap-select-jquery.min.js', + }, + 'main': { + 'source_filenames': ( + 'tfjm/js/main.js', + 'tfjm/js/theme.js', + ), + 'output_filename': 'tfjm/js/main.min.js', + }, + 'theme': { + 'source_filenames': ( + 'tfjm/js/theme.js', + ), + 'output_filename': 'tfjm/js/theme.min.js', + }, + 'chat': { + 'source_filenames': ( + 'tfjm/js/chat.js', + ), + 'output_filename': 'tfjm/js/chat.min.js', + }, + 'draw': { + 'source_filenames': ( + 'tfjm/js/draw.js', + ), + 'output_filename': 'tfjm/js/draw.min.js', + }, + }, + 'STYLESHEETS': { + 'bootstrap_fontawesome': { + 'source_filenames': ( + 'bootstrap/css/bootstrap.min.css', + 'fontawesome/css/all.css', + 'fontawesome/css/v4-shims.css', + 'bootstrap-select/css/bootstrap-select.min.css', + ), + 'output_filename': 'tfjm/css/bootstrap_fontawesome.min.css', + } + }, +} + MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, "media") diff --git a/tfjm/static/Fiche_sanitaire.pdf b/tfjm/static/tfjm/Fiche_sanitaire.pdf similarity index 100% rename from tfjm/static/Fiche_sanitaire.pdf rename to tfjm/static/tfjm/Fiche_sanitaire.pdf diff --git a/tfjm/static/Fiche_synthèse.docx b/tfjm/static/tfjm/Fiche_synthèse.docx similarity index 100% rename from tfjm/static/Fiche_synthèse.docx rename to tfjm/static/tfjm/Fiche_synthèse.docx diff --git a/tfjm/static/Fiche_synthèse.odt b/tfjm/static/tfjm/Fiche_synthèse.odt similarity index 100% rename from tfjm/static/Fiche_synthèse.odt rename to tfjm/static/tfjm/Fiche_synthèse.odt diff --git a/tfjm/static/Fiche_synthèse.pdf b/tfjm/static/tfjm/Fiche_synthèse.pdf similarity index 100% rename from tfjm/static/Fiche_synthèse.pdf rename to tfjm/static/tfjm/Fiche_synthèse.pdf diff --git a/tfjm/static/Fiche_synthèse.tex b/tfjm/static/tfjm/Fiche_synthèse.tex similarity index 100% rename from tfjm/static/Fiche_synthèse.tex rename to tfjm/static/tfjm/Fiche_synthèse.tex diff --git a/tfjm/static/logo.png b/tfjm/static/tfjm/img/logo.png similarity index 100% rename from tfjm/static/logo.png rename to tfjm/static/tfjm/img/logo.png diff --git a/tfjm/static/logo_animath.png b/tfjm/static/tfjm/img/logo_animath.png similarity index 100% rename from tfjm/static/logo_animath.png rename to tfjm/static/tfjm/img/logo_animath.png diff --git a/tfjm/static/logo_animath.svg b/tfjm/static/tfjm/img/logo_animath.svg similarity index 100% rename from tfjm/static/logo_animath.svg rename to tfjm/static/tfjm/img/logo_animath.svg diff --git a/tfjm/static/tfjm-192.png b/tfjm/static/tfjm/img/tfjm-192.png similarity index 100% rename from tfjm/static/tfjm-192.png rename to tfjm/static/tfjm/img/tfjm-192.png diff --git a/tfjm/static/tfjm-512.png b/tfjm/static/tfjm/img/tfjm-512.png similarity index 100% rename from tfjm/static/tfjm-512.png rename to tfjm/static/tfjm/img/tfjm-512.png diff --git a/tfjm/static/tfjm-square.svg b/tfjm/static/tfjm/img/tfjm-square.svg similarity index 100% rename from tfjm/static/tfjm-square.svg rename to tfjm/static/tfjm/img/tfjm-square.svg diff --git a/tfjm/static/tfjm.svg b/tfjm/static/tfjm/img/tfjm.svg similarity index 100% rename from tfjm/static/tfjm.svg rename to tfjm/static/tfjm/img/tfjm.svg diff --git a/tfjm/static/main.js b/tfjm/static/tfjm/js/main.js similarity index 100% rename from tfjm/static/main.js rename to tfjm/static/tfjm/js/main.js diff --git a/tfjm/static/theme.js b/tfjm/static/tfjm/js/theme.js similarity index 100% rename from tfjm/static/theme.js rename to tfjm/static/tfjm/js/theme.js diff --git a/tfjm/templates/base.html b/tfjm/templates/base.html index da1cff5..d375480 100644 --- a/tfjm/templates/base.html +++ b/tfjm/templates/base.html @@ -1,4 +1,6 @@ -{% load i18n static %} +{% load i18n %} +{% load pipeline %} +{% load static %} {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %} @@ -16,19 +18,12 @@ {# Bootstrap CSS #} - - - - - + {% stylesheet 'bootstrap_fontawesome' %} {# Bootstrap JavaScript #} - - + {% javascript 'bootstrap' %} {# bootstrap-select for beautiful selects and JQuery dependency #} - - - + {% javascript 'bootstrap_select' %} {# Si un formulaire requiert des données supplémentaires (notamment JS), les données sont chargées #} {% if form.media %} @@ -87,8 +82,7 @@ {% include "base_modal.html" with modal_id="login" %} {% endif %} - - +{% javascript 'main' %}