{% extends 'partials/base.html.twig' %} {% block content %} {% 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 road — past trip uses declared date_end; active trip uses first entry to now #} {% set days_on_road = 0 %} {% 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 %} {% endif %} {# Countries — unique, case-insensitive dedup, preserve original casing #} {% set seen_lower = [] %} {% set country_display = [] %} {% for entry in all_entries %} {% if entry.header.location_country is not empty %} {% set lower = entry.header.location_country|trim|lower %} {% if lower not in seen_lower %} {% set seen_lower = seen_lower|merge([lower]) %} {% set country_display = country_display|merge([entry.header.location_country|trim]) %} {% endif %} {% 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 %} {% if entry.header.lat is not empty and entry.header.lng is not empty %} {% set gps_points = gps_points|merge([[entry.header.lat, entry.header.lng]]) %} {% 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 %}
{{ has_gpx ? 'Distance based on GPS track data.' : 'Distance is approximate — straight lines between entry locations.' }}