diff --git a/themes/intotheeast/css/style.css b/themes/intotheeast/css/style.css index cb63987..b89ecfc 100644 --- a/themes/intotheeast/css/style.css +++ b/themes/intotheeast/css/style.css @@ -467,11 +467,15 @@ body::after { .stats-grid { display: grid; - grid-template-columns: repeat(2, 1fr); + grid-template-columns: repeat(3, 1fr); gap: var(--space-4); margin-bottom: var(--space-8); } +@media (max-width: 600px) { + .stats-grid { grid-template-columns: repeat(2, 1fr); } +} + .stat-block { background: var(--color-canvas); border: 1px solid var(--color-border); diff --git a/themes/intotheeast/templates/stats.html.twig b/themes/intotheeast/templates/stats.html.twig index 9a83c33..afafe59 100644 --- a/themes/intotheeast/templates/stats.html.twig +++ b/themes/intotheeast/templates/stats.html.twig @@ -1,26 +1,32 @@ {% extends 'partials/base.html.twig' %} {% block content %} -{% set tracker_page = grav.pages.find(page.parent().route ~ '/dailies') %} +{% set trip_page = page.parent() %} +{% set tracker_page = grav.pages.find(trip_page.route ~ '/dailies') %} {% set all_entries = tracker_page ? tracker_page.children.published() : [] %} {# Basic counts #} {% set entry_count = all_entries|length %} -{# Days on the road — find earliest entry timestamp by iterating #} +{# Days on road — past trip uses declared date_end; active trip uses first entry to now #} {% set days_on_road = 0 %} -{% set first_ts = null %} -{% for entry in all_entries %} - {% set ts = entry.date|date('U') %} - {% if first_ts is null or ts < first_ts %} - {% set first_ts = ts %} +{% if trip_page.header.date_end is not empty %} + {# Past trip: use declared end date #} + {% set start_ts = trip_page.header.date_start|date('U') %} + {% set end_ts = trip_page.header.date_end|date('U') %} + {% set days_on_road = ((end_ts - start_ts) / 86400)|round(0, 'ceil') %} +{% else %} + {# Active trip: first entry to now #} + {% set first_ts = null %} + {% for entry in all_entries %} + {% set ts = entry.date|date('U') %} + {% if first_ts is null or ts < first_ts %}{% set first_ts = ts %}{% endif %} + {% endfor %} + {% if first_ts is not null %} + {% set diff_seconds = "now"|date('U') - first_ts %} + {% set days_raw = (diff_seconds / 86400)|round(0, 'floor') %} + {% set days_on_road = days_raw < 1 ? 1 : days_raw %} {% endif %} -{% endfor %} -{% if first_ts is not null %} - {% set now_ts = "now"|date('U') %} - {% set diff_seconds = now_ts - first_ts %} - {% set days_raw = (diff_seconds / 86400)|round(0, 'floor') %} - {% set days_on_road = days_raw < 1 ? 1 : days_raw %} {% endif %} {# Countries — unique, case-insensitive dedup, preserve original casing #} @@ -36,6 +42,30 @@ {% endif %} {% endfor %} +{# Cities — unique, case-insensitive dedup, preserve original casing #} +{% set seen_city_lower = [] %} +{% set city_display = [] %} +{% for entry in all_entries %} + {% if entry.header.location_city is not empty %} + {% set lower = entry.header.location_city|trim|lower %} + {% if lower not in seen_city_lower %} + {% set seen_city_lower = seen_city_lower|merge([lower]) %} + {% set city_display = city_display|merge([entry.header.location_city|trim]) %} + {% endif %} + {% endif %} +{% endfor %} + +{# Temperature range #} +{% set temp_min = null %} +{% set temp_max = null %} +{% for entry in all_entries %} + {% if entry.header.weather_temp_c is defined and entry.header.weather_temp_c is not empty %} + {% set t = entry.header.weather_temp_c %} + {% if temp_min is null or t < temp_min %}{% set temp_min = t %}{% endif %} + {% if temp_max is null or t > temp_max %}{% set temp_max = t %}{% endif %} + {% endif %} +{% endfor %} + {# GPS points for distance — collect as JSON for JS computation #} {% set gps_points = [] %} {% for entry in all_entries %} @@ -44,6 +74,15 @@ {% endif %} {% endfor %} +{# GPX detection — trip has GPX files if any .gpx media exists on the trip page #} +{% set gpx_urls = [] %} +{% for name, media in trip_page.media.all %} + {% if name|split('.')|last == 'gpx' %} + {% set gpx_urls = gpx_urls|merge([trip_page.url ~ '/' ~ name]) %} + {% endif %} +{% endfor %} +{% set has_gpx = gpx_urls|length > 0 %} +
Distance is approximate — straight lines between entry locations.
+{{ has_gpx ? 'Distance based on GPS track data.' : 'Distance is approximate — straight lines between entry locations.' }}
{% endblock %}