189 lines
8.4 KiB
Twig
189 lines
8.4 KiB
Twig
{% extends 'default.html.twig' %}
|
|
|
|
{% block content %}
|
|
{% set journal_entries = page.collection() %}
|
|
{% set stories_page = grav.pages.find(page.parent().route ~ '/stories') %}
|
|
{% set story_entries = stories_page ? stories_page.children.published() : [] %}
|
|
|
|
{% set all_items = [] %}
|
|
{% for e in journal_entries %}
|
|
{% set all_items = all_items|merge([{'type': 'journal', 'page': e, 'date': e.date}]) %}
|
|
{% endfor %}
|
|
{% for s in story_entries %}
|
|
{% set all_items = all_items|merge([{'type': 'story', 'page': s, 'date': s.date}]) %}
|
|
{% endfor %}
|
|
|
|
{# No sort needed: page.collection() returns journal entries date-descending per dailies.md config. Dailies has no stories, so no re-merge sort is needed. #}
|
|
|
|
{# Collect GPS entries for mini-map #}
|
|
{% set map_entries = [] %}
|
|
{% for item in all_items %}
|
|
{% if item.type == 'journal' and item.page.header.lat is not empty and item.page.header.lng is not empty %}
|
|
{% set map_entries = map_entries|merge([{
|
|
'lat': item.page.header.lat,
|
|
'lng': item.page.header.lng,
|
|
'title': item.page.title,
|
|
'slug': item.page.slug,
|
|
'url': item.page.url,
|
|
'force_connect': item.page.header.force_connect ? true : false,
|
|
'transport_mode': item.page.header.transport_mode ? item.page.header.transport_mode : null
|
|
}]) %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
{# Collect GPX URLs from parent trip page for connector algorithm #}
|
|
{% set trip_page = page.parent() %}
|
|
{% 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 %}
|
|
|
|
{% if map_entries|length > 0 %}
|
|
<div class="feed-map-wrap">
|
|
<div class="feed-map" id="feed-map"></div>
|
|
<a class="feed-map-link" href="{{ page.parent().url }}/map">View full map →</a>
|
|
</div>
|
|
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maplibre-gl@4/dist/maplibre-gl.css">
|
|
<script src="https://cdn.jsdelivr.net/npm/maplibre-gl@4/dist/maplibre-gl.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/@mapbox/togeojson@0.16.2/togeojson.min.js"></script>
|
|
<script src="{{ url('theme://js/maplibre-utils.js') }}"></script>
|
|
<script>
|
|
var FEED_ENTRIES = {{ map_entries|json_encode|raw }};
|
|
var GPX_URLS = {{ gpx_urls|json_encode|raw }};
|
|
|
|
var feedMap = new maplibregl.Map({
|
|
container: 'feed-map',
|
|
style: MapUtils.MAP_STYLE,
|
|
center: [20, 20],
|
|
zoom: 2
|
|
});
|
|
|
|
feedMap.on('load', function () {
|
|
var bounds = new maplibregl.LngLatBounds();
|
|
|
|
FEED_ENTRIES.forEach(function (entry, i) {
|
|
var isLatest = (i === FEED_ENTRIES.length - 1);
|
|
var lngLat = [parseFloat(entry.lng), parseFloat(entry.lat)];
|
|
bounds.extend(lngLat);
|
|
|
|
var el = MapUtils.createDotMarker(isLatest);
|
|
el.dataset.url = entry.url;
|
|
var popup = new maplibregl.Popup({ offset: 12, closeButton: false, closeOnClick: false, className: 'map-tip-popup' })
|
|
.setLngLat(lngLat)
|
|
.setHTML('<span class="map-tip">' + entry.title + '</span>');
|
|
el.addEventListener('mouseenter', function () { popup.addTo(feedMap); });
|
|
el.addEventListener('mouseleave', function () { popup.remove(); });
|
|
el.addEventListener('click', function () { window.location.href = entry.url; });
|
|
|
|
new maplibregl.Marker({ element: el }).setLngLat(lngLat).addTo(feedMap);
|
|
});
|
|
|
|
if (FEED_ENTRIES.length === 1) {
|
|
feedMap.jumpTo({ center: [parseFloat(FEED_ENTRIES[0].lng), parseFloat(FEED_ENTRIES[0].lat)], zoom: 10 });
|
|
} else {
|
|
feedMap.fitBounds(bounds, { padding: 60, maxZoom: 11 });
|
|
}
|
|
|
|
Promise.all(GPX_URLS.map(function (url, idx) {
|
|
return fetch(url)
|
|
.then(function (r) { return r.text(); })
|
|
.then(function (text) {
|
|
var xml = new DOMParser().parseFromString(text, 'text/xml');
|
|
var geojson = toGeoJSON.gpx(xml);
|
|
return MapUtils.extractTrackpoints(geojson);
|
|
})
|
|
.catch(function (err) {
|
|
console.warn('GPX load failed (feed-map):', url, err);
|
|
return [];
|
|
});
|
|
})).then(function (allTrackpoints) {
|
|
var validTrackpoints = allTrackpoints.filter(function (tp) { return tp.length > 0; });
|
|
var segments = MapUtils.buildJourneySegments(FEED_ENTRIES, validTrackpoints, 10);
|
|
MapUtils.addJourneySegments(feedMap, segments, 'feed-journey');
|
|
});
|
|
});
|
|
</script>
|
|
{% endif %}
|
|
|
|
<div class="feed">
|
|
{% if all_items|length > 0 %}
|
|
{% for item in all_items %}
|
|
{% set entry = item.page %}
|
|
{% set hero = null %}
|
|
{% if entry.header.hero_image and entry.media[entry.header.hero_image] is defined %}
|
|
{% set hero = entry.media[entry.header.hero_image] %}
|
|
{% elseif entry.media.images|length > 0 %}
|
|
{% set hero = entry.media.images|first %}
|
|
{% endif %}
|
|
|
|
{% if item.type == 'journal' %}
|
|
{% set weather_icons = {
|
|
'Sunny': '☀️', 'Partly cloudy': '⛅', 'Cloudy': '☁️',
|
|
'Foggy': '🌫️', 'Drizzle': '🌦️', 'Rain': '🌧️',
|
|
'Snow': '❄️', 'Thunderstorm': '⛈️'
|
|
} %}
|
|
<article class="journal-post" id="entry-{{ entry.slug }}" data-type="journal" data-lat="{{ entry.header.lat }}" data-lng="{{ entry.header.lng }}">
|
|
<header class="journal-post-header">
|
|
<h2 class="journal-post-title">{{ entry.title }}</h2>
|
|
<p class="journal-post-meta">
|
|
<a class="journal-post-permalink" href="{{ entry.url }}">
|
|
<time datetime="{{ entry.date|date('Y-m-d') }}">{{ entry.date|date('d M Y')|upper }}</time>
|
|
</a>
|
|
{% if entry.header.location_city or entry.header.location_country %}
|
|
<span class="journal-post-location">
|
|
· 📍
|
|
{%- set _loc = [] -%}
|
|
{%- if entry.header.location_city -%}{%- set _loc = _loc|merge([entry.header.location_city]) -%}{%- endif -%}
|
|
{%- if entry.header.location_country -%}{%- set _loc = _loc|merge([entry.header.location_country]) -%}{%- endif -%}
|
|
{{ _loc|join(', ') }}
|
|
</span>
|
|
{% endif %}
|
|
{% if entry.header.weather_desc %}
|
|
<span class="journal-post-weather">· {{ weather_icons[entry.header.weather_desc] ?? '' }} {{ entry.header.weather_desc }}</span>
|
|
{% endif %}
|
|
</p>
|
|
</header>
|
|
|
|
{% set images = entry.media.images %}
|
|
{% if images|length > 0 %}
|
|
<div class="journal-photo-strip" data-slides="{{ images|length }}">
|
|
{% for img in images %}
|
|
<div class="journal-photo-slide">
|
|
<img src="{{ img.cropResize(900, 600).url }}" alt="{{ entry.title }}" loading="lazy">
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
{% if images|length > 1 %}
|
|
<div class="journal-photo-dots" aria-hidden="true">
|
|
{% for img in images %}
|
|
<span class="journal-photo-dot{% if loop.first %} is-active{% endif %}"></span>
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
<div class="journal-post-body">{{ entry.content|raw }}</div>
|
|
</article>
|
|
{% else %}
|
|
<a class="entry-card entry-card--story" id="entry-{{ entry.slug }}" data-type="story" href="{{ entry.url }}">
|
|
{% if hero %}
|
|
<div class="entry-card-photo entry-card-photo--story">
|
|
<img src="{{ hero.cropResize(720, 405).url }}" alt="{{ entry.title }}" loading="lazy">
|
|
</div>
|
|
{% endif %}
|
|
<div class="entry-card-body">
|
|
<span class="story-badge">✦ Story</span>
|
|
<h2 class="entry-title">{{ entry.title }}</h2>
|
|
</div>
|
|
</a>
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% else %}
|
|
<p class="feed-empty">No entries yet. The journey is about to begin.</p>
|
|
{% endif %}
|
|
</div>
|
|
{% endblock %}
|