forked from rDrama/rDrama
1
0
Fork 0

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.
master
Snakes 2022-05-26 22:47:32 -04:00
parent 2bde3650d4
commit af77ec515d
12 changed files with 34 additions and 22 deletions

View File

@ -1,3 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
@ -15,7 +16,7 @@
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=57">
{% if v.agendaposter %}
<style>
@ -40,7 +41,7 @@
{% endif %}
{% else %}
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=57">
{% endif %}

View File

@ -1,3 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
<head>
@ -14,7 +15,7 @@
<title>Chat</title>
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=57">
{% if v.css %}
<link rel="stylesheet" href="/@{{v.username}}/css">

View File

@ -1,3 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
<head>
@ -7,7 +8,7 @@
<script src="/assets/js/bootstrap.js?v=252"></script>
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=58">
<link rel="stylesheet" href="/assets/css/awards.css?v=7">
{% if v.agendaposter %}
@ -33,7 +34,7 @@
{% endif %}
{% else %}
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=57">
<link rel="stylesheet" href="/assets/css/awards.css?v=7">
{% endif %}

View File

@ -6,7 +6,7 @@
{% block content %}
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=57">
{% if v.agendaposter %}
<style>
@ -31,7 +31,7 @@
{% endif %}
{% else %}
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=57">
{% endif %}

View File

@ -1,4 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
@ -18,7 +18,7 @@
{% endblock %}
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=57">
</head>

View File

@ -1,4 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
@ -14,7 +14,7 @@
<title>2-Step Login - {{SITE_NAME}}</title>
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=57">
</head>

View File

@ -1,4 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
<head>
@ -34,7 +34,7 @@
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=57">
{% if v.agendaposter %}
<style>

View File

@ -1,4 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
@ -39,11 +39,11 @@
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=57">
{% else %}
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=57">
{% endif %}
</head>

View File

@ -1,4 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
<head>
@ -31,7 +31,7 @@
<title>{% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}Sign up - {{SITE_NAME}}{% endif %}</title>
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=57">
</head>

View File

@ -1,4 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
@ -32,7 +32,7 @@
<title>{% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}{{SITE_NAME}}{% endif %}</title>
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=57">
</head>

View File

@ -1,3 +1,4 @@
{%- from 'util/assetcache.html' import asset -%}
<!DOCTYPE html>
<html lang="en">
<head>
@ -26,7 +27,7 @@
{% block stylesheets %}
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=49">
{% if v.agendaposter %}
<style>
@ -51,7 +52,7 @@
{% endif %}
{% else %}
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=275">
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=49">
{% endif %}
{% endblock %}

View File

@ -0,0 +1,8 @@
{%-
set CACHE_VER = {
'css/main.css': 276,
}
-%}
{%- macro asset(name) -%}
/assets/{{name}}?v={{ CACHE_VER[name] }}
{%- endmacro -%}