From af77ec515d2c2919f621b68abbbe8173fceac78c Mon Sep 17 00:00:00 2001 From: TLSM Date: Thu, 26 May 2022 22:47:32 -0400 Subject: [PATCH] Templates: create assetcache template. For too long, we've Replace-All'd to increment site asset version numbers. This is a task that has an obvious solution using the templating engine. As such, we now have templates/util/assetcache.html which contains a dict of version numbers and a macro to generate the versioned name of an asset. Going forward, it is recommended that all future replace-all uses are used as opportunities to switch to the macro. Do remember to import the macro in all top-level templates, if not already present. Recommended form: {%- from 'util/assetcache.html' import asset -%} Then add a key to CACHE_VER in util/assetcache.html. Then replace the asset path in templates eg: {{asset('css/main.css')}} For all future versions of those assets, one can simply increment the value in util/assetcache.html instead. This will greatly reduce git spam touching unrelated files and generally be clearer and easier. --- files/templates/authforms.html | 5 +++-- files/templates/chat.html | 3 ++- files/templates/default.html | 5 +++-- files/templates/log.html | 4 ++-- files/templates/login.html | 4 ++-- files/templates/login_2fa.html | 4 ++-- files/templates/settings.html | 4 ++-- files/templates/settings2.html | 6 +++--- files/templates/sign_up.html | 4 ++-- files/templates/sign_up_failed_ref.html | 4 ++-- files/templates/submit.html | 5 +++-- files/templates/util/assetcache.html | 8 ++++++++ 12 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 files/templates/util/assetcache.html diff --git a/files/templates/authforms.html b/files/templates/authforms.html index c364aa1657..e6cc066643 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -1,3 +1,4 @@ +{%- from 'util/assetcache.html' import asset -%} @@ -15,7 +16,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/chat.html b/files/templates/chat.html index 49900f195f..362476c1fe 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -1,3 +1,4 @@ +{%- from 'util/assetcache.html' import asset -%} @@ -14,7 +15,7 @@ Chat - + {% if v.css %} diff --git a/files/templates/default.html b/files/templates/default.html index c2f2bf9b6c..ebb72691de 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -1,3 +1,4 @@ +{%- from 'util/assetcache.html' import asset -%} @@ -7,7 +8,7 @@ {% if v %} - + {% if v.agendaposter %} @@ -33,7 +34,7 @@ {% endif %} {% else %} - + {% endif %} diff --git a/files/templates/log.html b/files/templates/log.html index 592274cb1b..9aa7332c25 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/login.html b/files/templates/login.html index 11e90e72c9..aaad11cbba 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -1,4 +1,4 @@ - +{%- from 'util/assetcache.html' import asset -%} @@ -18,7 +18,7 @@ {% endblock %} - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index e1d3ce5c1d..dfc197f1ef 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -1,4 +1,4 @@ - +{%- from 'util/assetcache.html' import asset -%} @@ -14,7 +14,7 @@ 2-Step Login - {{SITE_NAME}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 1290cfc109..51f1692e11 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -1,4 +1,4 @@ - +{%- from 'util/assetcache.html' import asset -%} @@ -34,7 +34,7 @@ - + {% if v.agendaposter %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index c2386b0926..9fd64071a9 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -1,4 +1,4 @@ - +{%- from 'util/assetcache.html' import asset -%} @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}Sign up - {{SITE_NAME}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index dff546bf77..a0f5b322fc 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -1,4 +1,4 @@ - +{%- from 'util/assetcache.html' import asset -%} @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}{{SITE_NAME}}{% endif %} - + diff --git a/files/templates/submit.html b/files/templates/submit.html index 5dc6f17ff9..6435867d21 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -1,3 +1,4 @@ +{%- from 'util/assetcache.html' import asset -%} @@ -26,7 +27,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - + {% endif %} {% endblock %} diff --git a/files/templates/util/assetcache.html b/files/templates/util/assetcache.html new file mode 100644 index 0000000000..2448ead32f --- /dev/null +++ b/files/templates/util/assetcache.html @@ -0,0 +1,8 @@ +{%- +set CACHE_VER = { + 'css/main.css': 276, +} +-%} +{%- macro asset(name) -%} +/assets/{{name}}?v={{ CACHE_VER[name] }} +{%- endmacro -%} \ No newline at end of file