diff --git a/pages/04.stats/stats.md b/pages/04.stats/stats.md new file mode 100644 index 0000000..1a772e7 --- /dev/null +++ b/pages/04.stats/stats.md @@ -0,0 +1,4 @@ +--- +title: 'Trip Stats' +template: stats +--- diff --git a/themes/intotheeast/templates/stats.html.twig b/themes/intotheeast/templates/stats.html.twig new file mode 100644 index 0000000..ee0bf6f --- /dev/null +++ b/themes/intotheeast/templates/stats.html.twig @@ -0,0 +1,107 @@ +{% extends 'partials/base.html.twig' %} + +{% block content %} +{% set tracker_page = grav.pages.find('/tracker') %} +{% 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 #} +{% 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 %} + {% 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 #} +{% 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 %} + +{# 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 %} + +
+

Trip Statistics

+ +
+
+ {{ days_on_road }} + {{ days_on_road == 1 ? 'day' : 'days' }} on the road +
+
+ {{ entry_count }} + {{ entry_count == 1 ? 'entry' : 'entries' }} posted +
+
+ {{ country_display|length }} + {{ country_display|length == 1 ? 'country' : 'countries' }} visited +
+
+ + km traveled +
+
+ + {% if country_display|length > 0 %} +
+ Countries visited + {{ country_display|join(' · ') }} +
+ {% endif %} + +

Distance is approximate — straight lines between entry locations.

+
+ + +{% endblock %}