My personal site cherry.computer
htmx tailwind axum askama

refactor: destructure Options in templates with if let

cherry.computer aa6ca680 75784064

verified
+6 -9
+2 -3
server/templates/index.html
··· 92 92 sse-connect="/scrobbles{% if scrobble.is_none() %}?immediate=true{% endif %}" 93 93 sse-swap="scrobble" 94 94 > 95 - {%- match scrobble %} {%- when Some with (ScrobblesTemplate {intro, now_playing, image, srcset}) %} 95 + {%- if let Some(ScrobblesTemplate {intro, now_playing, image, srcset}) = scrobble %} 96 96 {% include "scrobble.html" %} 97 - {%- else %} 98 - {%- endmatch %} 97 + {%- endif %} 99 98 </div> 100 99 </body> 101 100 </html>
+4 -6
server/templates/scrobble.html
··· 1 1 <div class="bar-container"> 2 - {%- match image %} {%- when Some with (image) %} 2 + {%- if let Some(image) = image %} 3 3 <img 4 4 class="bar-cover" 5 5 src="{{ image }}" 6 6 alt="Cover art" 7 - {%- match srcset %} {%- when Some with (srcset) %} 7 + {%- if let Some(srcset) = srcset %} 8 8 srcset="{{ srcset }}" 9 - {%- else %} 10 - {%- endmatch %} 9 + {%- endif %} 11 10 /> 12 - {%- else %} 13 - {%- endmatch %} 11 + {%- endif %} 14 12 <p class="bar-text-intro">{{ intro }}</p> 15 13 <p class="bar-text-music">{{ now_playing }}</p> 16 14 </div>