refactor: extract date range macro; fix stories.html.twig asset registration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vgmzx8VTTTmCskSpQtsLTr
This commit is contained in:
2026-06-24 00:07:26 +02:00
parent 04bcab2d55
commit 24ffa42499
3 changed files with 28 additions and 20 deletions
@@ -0,0 +1,19 @@
{% macro format_date_range(start_date, end_date) %}
{%- if end_date is not empty and end_date|date('Y-m-d') != start_date|date('Y-m-d') -%}
{%- set sd = start_date|date('d') -%}
{%- set sm = start_date|date('M') -%}
{%- set sy = start_date|date('Y') -%}
{%- set ed = end_date|date('d') -%}
{%- set em = end_date|date('M') -%}
{%- set ey = end_date|date('Y') -%}
{%- if sy == ey and sm == em -%}
{{- sd ~ ' ' ~ ed ~ ' ' ~ em ~ ' ' ~ ey -}}
{%- elseif sy == ey -%}
{{- sd ~ ' ' ~ sm ~ ' ' ~ ed ~ ' ' ~ em ~ ' ' ~ ey -}}
{%- else -%}
{{- sd ~ ' ' ~ sm ~ ' ' ~ sy ~ ' ' ~ ed ~ ' ' ~ em ~ ' ' ~ ey -}}
{%- endif -%}
{%- else -%}
{{- start_date|date('d M Y') -}}
{%- endif %}
{% endmacro %}
@@ -1,6 +1,12 @@
{% extends 'partials/base.html.twig' %}
{% block map_assets %}
{% do assets.addCss('theme://css-compiled/map.css') %}
{% do assets.addJs('theme://js/map.js', {group: 'bottom'}) %}
{% endblock %}
{% block content %}
{% import 'macros/date-range.html.twig' as dr_m %}
{% set stories = page.children.published().order('date', 'asc') %}
{# Collect stories that have coordinates for the mini-map #}
@@ -46,10 +52,7 @@
{% set hero = story.media[story.header.hero_image] %}
{% endif %}
{% set date_str = story.date|date('d M Y') %}
{% if story.header.end_date %}
{% set date_str = story.date|date('d M') ~ '' ~ story.header.end_date|date('d M Y') %}
{% endif %}
{% set date_str = dr_m.format_date_range(story.date, story.header.end_date ?? null) %}
<a class="story-card" id="story-{{ story.slug }}" href="{{ story.url }}">
{% if hero %}
+2 -16
View File
@@ -6,6 +6,7 @@
{% endblock %}
{% block content %}
{% import 'macros/date-range.html.twig' as dr_m %}
{% set hero_url = null %}
{% if page.header.hero_image %}
{% if page.media[page.header.hero_image] is defined %}
@@ -16,22 +17,7 @@
{% endif %}
{% endif %}
{% set date_str = page.date|date('d M Y') %}
{% if page.header.end_date and page.header.end_date|date('Y-m-d') != page.date|date('Y-m-d') %}
{% set sd = page.date|date('d') %}
{% set sm = page.date|date('M') %}
{% set sy = page.date|date('Y') %}
{% set ed = page.header.end_date|date('d') %}
{% set em = page.header.end_date|date('M') %}
{% set ey = page.header.end_date|date('Y') %}
{% if sy == ey and sm == em %}
{% set date_str = sd ~ ' ' ~ ed ~ ' ' ~ em ~ ' ' ~ ey %}
{% elseif sy == ey %}
{% set date_str = sd ~ ' ' ~ sm ~ ' ' ~ ed ~ ' ' ~ em ~ ' ' ~ ey %}
{% else %}
{% set date_str = sd ~ ' ' ~ sm ~ ' ' ~ sy ~ ' ' ~ ed ~ ' ' ~ em ~ ' ' ~ ey %}
{% endif %}
{% endif %}
{% set date_str = dr_m.format_date_range(page.date, page.header.end_date ?? null) %}
{% set location = page.header.location_name ?? '' %}