{# Owner gate (R1): broader than trip.html.twig's owner_can_edit — publishing
works on ANY trip, not just the active one, so it's just owner identity. #}
{% set is_owner = grav.user.authenticated
and grav.user.username == grav.config.site.owner_username %}
{# Owner sees drafts (R9); everyone else published only. #}
{% set trips = (is_owner ? page.children : page.children.published())|sort((a, b) => a.date < b.date ? 1 : -1) %}
{% if is_owner %}{% do assets.addJs('theme://js/trip-publish.js', {group: 'bottom'}) %}{% endif %}
{% if trips|length == 0 %}
No trips yet.
{% else %}
{% for trip in trips %}
{% set dailies_page = grav.pages.find(trip.route ~ '/dailies') %}
{% set stories_page = grav.pages.find(trip.route ~ '/stories') %}
{% set journal_count = dailies_page ? dailies_page.children.published()|length : 0 %}
{% set story_count = stories_page ? stories_page.children.published()|length : 0 %}
{# Robust active-trip match: site.active_trip may be a full route
(/trips/x) or a bare slug — normalise both sides before comparing so the
R12 confirm never silently drops (both forms exist in helpers.js /
cache-on-save). #}
{% set active = (config.site.active_trip ?? '')|trim('/') %}
{% set trip_route = trip.route|trim('/') %}
{% set is_active = active != '' and (active == trip_route or active == ('trips/' ~ trip.slug) or active == trip.slug) %}
{# The wrapper is a positioned container so the owner toggle can overlay the
cover as a SIBLING of the navigating (KTD6) — and it exists even for a
coverless draft, giving the toggle an anchor whether or not the cover macro
emits an image. #}