assetcache: Add dynamic file parameter, apply more.

Assetcache macro improvement: to support assets in folders which are
dynamically referenced by e.g. ID or name, the `asset` macro now
accepts an optional second parameter to be included in the path but
not to be used for versioning the class of assets.

To support recent commits, assetcache now applies for:
  - images/badges/*.webp
  - js/: award_modal.js, bootstrap.js, header.js
remotes/1693045480750635534/spooky-22
Snakes 2022-05-29 00:52:40 -04:00
parent bbca69620d
commit 0aafd810a2
15 changed files with 21 additions and 17 deletions

View File

@ -60,7 +60,7 @@
<label class="custom-control-label" for="{{badge.id}}"></label>
</div>
</td>
<td><label for="badge-{{badge.id}}"><img alt="{{badge.name}}" loading="lazy" src="/assets/images/badges/{{badge.id}}.webp?v=1016" width=64.16 height=70></label></td>
<td><label for="badge-{{badge.id}}"><img alt="{{badge.name}}" loading="lazy" src="{{asset('images/badges/', badge.id|string+'.webp')}}" width=64.16 height=70></label></td>
<td>{{badge.name}}</td>
<td>{{badge.description}}</td>
</tr>

View File

@ -60,7 +60,7 @@
<label class="custom-control-label" for="{{badge.id}}"></label>
</div>
</td>
<td><label for="badge-{{badge.id}}"><img alt="{{badge.name}}" loading="lazy" src="/assets/images/badges/{{badge.id}}.webp?v=1016" width=64.16 height=70></label></td>
<td><label for="badge-{{badge.id}}"><img alt="{{badge.name}}" loading="lazy" src="{{asset('images/badges/', badge.id|string+'.webp')}}" width=64.16 height=70></label></td>
<td>{{badge.name}}</td>
<td>{{badge.description}}</td>
</tr>

View File

@ -44,4 +44,4 @@
</div>
</div>
<script src="/assets/js/award_modal.js?v=249" data-cfasync="false"></script>
<script src="{{asset('js/award_modal.js')}}" data-cfasync="false"></script>

View File

@ -27,7 +27,7 @@
<tr>
<td>{{loop.index}}</td>
<td>{{badge.name}}</td>
<td><img alt="{{badge.name}}" loading="lazy" src="/assets/images/badges/{{badge.id}}.webp?v=1016" width=45.83 height=50>
<td><img alt="{{badge.name}}" loading="lazy" src="{{asset('images/badges/', badge.id|string+'.webp')}}" width=45.83 height=50>
<td>{{badge.description}}</td>
{%- set ct = counts[badge.id] if badge.id in counts else (0, 0) %}
<td class="badges-rarity-qty"><a href="/badge_owners/{{badge.id}}">{{ ct[0] }}</a></td>

View File

@ -106,7 +106,7 @@
</head>
<body>
<script src="/assets/js/bootstrap.js?v=255"></script>
<script src="{{asset('js/bootstrap.js')}}"></script>
{% include "header.html" %}

View File

@ -10,7 +10,7 @@
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; connect-src 'self'; object-src 'none';">
{% endif %}
<script src="/assets/js/bootstrap.js?v=255"></script>
<script src="{{asset('js/bootstrap.js')}}"></script>
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="{{asset('css/main.css')}}">

View File

@ -271,7 +271,7 @@
</div>
</nav>
<script src="/assets/js/header.js?v=266"></script>
<script src="{{asset('js/header.js')}}"></script>
{% if v and not err %}
<div id="formkey" class="d-none">{{v.formkey}}</div>

View File

@ -8,7 +8,7 @@
<meta name="description" content="{{config('DESCRIPTION')}}">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; connect-src 'self'; object-src 'none';">
<script src="/assets/js/bootstrap.js?v=255"></script>
<script src="{{asset('js/bootstrap.js')}}"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

View File

@ -14,7 +14,7 @@
<td>{{loop.index}}</td>
<td><a style="color:#{{u.namecolor}}" href="/@{{u.username}}"><img loading="lazy" src="{{u.profile_url}}" class="pp20"><span {% if u.patron %}class="patron" style="background-color:#{{u.namecolor}}"{% endif %}>{{u.username}}</span></a></td>
<td><img alt="2{{u.patron}}" loading="lazy" width=29.33 height=32 src="/assets/images/badges/2{{u.patron}}.webp?v=1016"></td>
<td><img alt="2{{u.patron}}" loading="lazy" width=29.33 height=32 src="{{asset('images/badges/', '2'+u.patron|string+'.webp')}}"></td>
</tr>
{% endfor %}
</table>

View File

@ -5,7 +5,7 @@
<meta name="description" content="{{config('DESCRIPTION')}}">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; connect-src 'self'; object-src 'none';">
<script src="/assets/js/bootstrap.js?v=255"></script>
<script src="{{asset('js/bootstrap.js')}}"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

View File

@ -6,7 +6,7 @@
<meta name="description" content="{{config('DESCRIPTION')}}">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; connect-src 'self'; object-src 'none';">
<script src="/assets/js/bootstrap.js?v=255"></script>
<script src="{{asset('js/bootstrap.js')}}"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

View File

@ -7,7 +7,7 @@
<meta name="description" content="{{config('DESCRIPTION')}}">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; connect-src 'self'; object-src 'none';">
<script src="/assets/js/bootstrap.js?v=255"></script>
<script src="{{asset('js/bootstrap.js')}}"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

View File

@ -8,7 +8,7 @@
<meta name="description" content="{{config('DESCRIPTION')}}">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; connect-src 'self'; object-src 'none';">
<script src="/assets/js/bootstrap.js?v=255"></script>
<script src="{{asset('js/bootstrap.js')}}"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

View File

@ -5,7 +5,7 @@
<meta name="description" content="{{config('DESCRIPTION')}}">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; connect-src 'self'; object-src 'none';">
<script src="/assets/js/bootstrap.js?v=255"></script>
<script src="{{asset('js/bootstrap.js')}}"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

View File

@ -1,8 +1,12 @@
{%-
set CACHE_VER = {
'css/main.css': 278,
'css/main.css': 279,
'js/award_modal.js': 250,
'js/bootstrap.js': 256,
'js/header.js': 267,
'images/badges/': 1017,
}
-%}
{%- macro asset(name) -%}
/assets/{{name}}?v={{ CACHE_VER[name] }}
{%- macro asset(name, file='') -%}
/assets/{{name}}{{file}}?v={{ CACHE_VER[name] }}
{%- endmacro -%}