source: Klonkt/src/views/shell.ejs@ abc8959

main
Last change on this file since abc8959 was 3038fc9, checked in by Robin Genis <roboburr@…>, 2 months ago

fix(images): list-cover placeholder in style.css (inline cascade didn't win) + buster v62

  • Property mode set to 100644
File size: 38.5 KB
RevLine 
[7bc636b]1<%
2// ── Helpers used inside this template ─────────────────────────────
3function _e(s) {
4 return String(s == null ? '' : s)
5 .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
6 .replace(/"/g, '&quot;').replace(/'/g, '&#39;');
7}
8
9const safeSite = site || {};
10const safeUrlBase = (typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '';
[9b851e7]11const safeAccent = safeSite.accent && /^#[0-9a-fA-F]{6}$/.test(safeSite.accent) ? safeSite.accent : '#e8b04b';
[7bc636b]12const lang = safeSite.language || 'nl';
13const ogLocale = safeSite.og_locale || (lang === 'nl' ? 'nl_NL' : (lang.length === 2 ? lang + '_' + lang.toUpperCase() : 'en_US'));
14const homePath = safeUrlBase + '/';
15const isPostPage = bodyClass && bodyClass.indexOf('on-post') >= 0;
16const isHomePage = bodyClass && bodyClass.indexOf('on-home') >= 0;
17const isSpecialPg = bodyClass && bodyClass.indexOf('on-special') >= 0;
18const isAdminPage = bodyClass && bodyClass.indexOf('on-admin') >= 0;
19
20// ── <title> via site.title_template ──────────────────────────────
21// Template: '{title} — {site}'. If pageTitle equals site.title (homepage) we
22// just use the site title alone, otherwise apply the template.
[5019e22]23const _siteTitle = safeSite.title || 'Klonkt';
[7bc636b]24const _rawTitle = pageTitle || _siteTitle;
25const _tpl = safeSite.title_template || '{title} — {site}';
26const _finalTitle = (_rawTitle === _siteTitle)
27 ? _siteTitle
28 : _tpl.replace('{title}', _rawTitle).replace('{site}', _siteTitle);
29
30// ── Robots: noindex on listing pages and on per-post override ─────
31let _shouldIndex = safeSite.robots_index !== 0;
32if (typeof post !== 'undefined' && post && post.noindex) _shouldIndex = false;
33// Listing pages (search/tag/type/archive) shouldn't be indexed (dupe content)
34if (currentPath) {
[8f2f97c]35 if (/^\/(?:search|tag|type|archive|users|account|admin)(?:$|\/)/.test(currentPath)) {
[7bc636b]36 _shouldIndex = false;
37 }
38}
39// Special-flagged views from routes opt out too
40if (isSpecialPg && (currentPath === '/search' || /^\/(tag|type|archive|users)\//.test(currentPath))) {
41 _shouldIndex = false;
42}
43
[1ff0043]44// ── Canonical URL: per-site override (admin SEO), else the .env base
45// (PUBLIC_BASE_URL, via ogOrigin → falls back to the request host) ──
[7bc636b]46let _canonical = null;
[1ff0043]47const _canonBase = safeSite.canonical || (typeof ogOrigin !== 'undefined' ? ogOrigin : '');
48if (_canonBase) {
49 const _base = _canonBase.replace(/\/+$/, '');
[7bc636b]50 let _path = '/';
51 if (typeof post !== 'undefined' && post && post.slug) _path = '/' + post.slug;
52 else if (currentPath) _path = currentPath;
53 _canonical = _base + _path;
54}
55
56// ── Social bits (OG/Twitter) ──────────────────────────────────────
57const _socialTitle = (typeof post !== 'undefined' && post && post.title) ? post.title : _siteTitle;
58const _socialDescr = (typeof socialDescr !== 'undefined' && socialDescr)
59 ? socialDescr
60 : (safeSite.default_description || safeSite.description || '');
[69815b2]61// og:image — custom (post/site) first; otherwise the auto-generated themed card
62// (/og/<slug>.png), so every site has a branded social preview by default.
63let _socialImage = '', _ogGenerated = false;
64if (typeof socialImage !== 'undefined' && socialImage) _socialImage = socialImage;
65else if (safeSite.og_image_default) _socialImage = safeSite.og_image_default;
66else if (safeSite.default_cover) _socialImage = safeSite.default_cover;
67else if (safeSite.slug && typeof ogOrigin !== 'undefined' && ogOrigin) {
68 _socialImage = ogOrigin + '/og/' + encodeURIComponent(safeSite.slug) + '.png';
69 _ogGenerated = true;
70}
[7bc636b]71const _ogType = isPostPage ? 'article' : 'website';
72
73// ── JSON-LD ───────────────────────────────────────────────────────
74const _publisher = {
75 '@type': safeSite.schema_type === 'Organization' ? 'Organization' : 'Person',
76 name: safeSite.publisher_name || _siteTitle,
77 url: safeSite.publisher_url || (_canonical ? _canonical.split(/(?<=^[^/]*\/\/[^/]+)\//)[0] + '/' : null),
78};
79if (safeSite.publisher_logo) {
80 _publisher.logo = { '@type': 'ImageObject', url: safeSite.publisher_logo };
81}
82let _jsonLd = null;
83if (typeof post !== 'undefined' && post && post.slug) {
84 _jsonLd = {
85 '@context': 'https://schema.org',
86 '@type': (post.type === 'foto' || post.type === 'video') ? 'CreativeWork' : 'Article',
87 headline: post.title || _siteTitle,
88 description: _socialDescr,
89 datePublished: post.published_at || post.created_at || new Date().toISOString(),
90 dateModified: post.updated_at || post.published_at || new Date().toISOString(),
91 publisher: _publisher,
92 };
93 if (_socialImage) _jsonLd.image = _socialImage;
94 if (post.author_username) _jsonLd.author = { '@type': 'Person', name: post.author_username };
95 if (Array.isArray(post.tags) && post.tags.length) _jsonLd.keywords = post.tags.join(', ');
96} else if (isHomePage) {
97 _jsonLd = {
98 '@context': 'https://schema.org',
99 '@type': 'WebSite',
100 name: _siteTitle,
101 description: safeSite.description || safeSite.default_description || '',
102 publisher: _publisher,
103 };
104}
105%><!DOCTYPE html>
[9cc0f9f]106<html lang="<%= _e(lang) %>" data-palette="<%= _e((typeof palette !== 'undefined' && palette) ? palette : (safeSite.palette || 'klonkt')) %>">
[7bc636b]107<head>
108<meta charset="utf-8">
[9217e4e]109<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
[7bc636b]110<meta name="color-scheme" content="dark light">
111
112<title><%= _finalTitle %></title>
113<meta name="description" content="<%= _e(_socialDescr) %>">
114<meta name="theme-color" content="<%= _e(safeAccent) %>">
115<meta name="robots" content="<%= _shouldIndex ? 'index,follow' : 'noindex,nofollow' %>">
116<% if (safeSite.author) { %><meta name="author" content="<%= _e(safeSite.author) %>"><% } %>
117<% if (_canonical) { %><link rel="canonical" href="<%= _e(_canonical) %>"><% } %>
118
119<!-- Search-engine verification -->
120<% if (safeSite.google_verification) { %><meta name="google-site-verification" content="<%= _e(safeSite.google_verification) %>"><% } %>
121<% if (safeSite.bing_verification) { %><meta name="msvalidate.01" content="<%= _e(safeSite.bing_verification) %>"><% } %>
122<% if (safeSite.pinterest_verification) { %><meta name="p:domain_verify" content="<%= _e(safeSite.pinterest_verification) %>"><% } %>
123<% if (safeSite.yandex_verification) { %><meta name="yandex-verification" content="<%= _e(safeSite.yandex_verification) %>"><% } %>
124
125<!-- Feed autodiscovery -->
126<% if (site) { %>
127<link rel="alternate" type="application/rss+xml" title="<%= _e(_siteTitle) %> — RSS" href="<%= _e(safeUrlBase + '/feed.xml') %>">
128<link rel="alternate" type="application/atom+xml" title="<%= _e(_siteTitle) %> — Atom" href="<%= _e(safeUrlBase + '/atom.xml') %>">
129<% } %>
130
131<!-- PWA -->
132<link rel="manifest" href="<%= _e(safeUrlBase + '/manifest.webmanifest') %>">
133<meta name="mobile-web-app-capable" content="yes">
134<meta name="apple-mobile-web-app-capable" content="yes">
135<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
136<meta name="apple-mobile-web-app-title" content="<%= _e(_siteTitle.slice(0, 16)) %>">
137<link rel="apple-touch-icon" href="<%= _e(safeSite.profile_photo || '/favicon.ico') %>">
[b5bae24]138<link rel="icon" type="image/svg+xml" href="/favicon.svg?v=sf">
139<link rel="alternate icon" href="/favicon.ico?v=sf">
[7bc636b]140
141<!-- OpenGraph -->
142<meta property="og:type" content="<%= _ogType %>">
143<meta property="og:title" content="<%= _e(_socialTitle) %>">
144<meta property="og:description" content="<%= _e(_socialDescr) %>">
145<meta property="og:site_name" content="<%= _e(_siteTitle) %>">
146<meta property="og:locale" content="<%= _e(ogLocale) %>">
147<% if (_socialImage) { %>
148<meta property="og:image" content="<%= _e(_socialImage) %>">
149<meta property="og:image:alt" content="<%= _e(_socialTitle) %>">
[69815b2]150<% if (_ogGenerated) { %>
151<meta property="og:image:width" content="1200">
152<meta property="og:image:height" content="630">
153<meta property="og:image:type" content="image/png">
154<% } %>
[7bc636b]155<% } %>
156<% if (_canonical) { %><meta property="og:url" content="<%= _e(_canonical) %>"><% } %>
[4c9c60b]157<%
158// Fediverse/social PLAYER card for posts with audio: instead of shipping the raw
159// mp3, point at our embeddable player (/embed?post=slug) so Mastodon shows an
160// inline player that streams via the gated /audio/stream (no downloadable file).
161const _postAudio = !!(typeof post !== 'undefined' && post
[30271e6]162 && typeof postHasPlayableAudio !== 'undefined' && postHasPlayableAudio
[4c9c60b]163 && typeof premiumUnlocked !== 'undefined' && premiumUnlocked);
164const _embedUrl = _postAudio
165 ? ((typeof ogOrigin !== 'undefined' && ogOrigin ? ogOrigin : '') + safeUrlBase + '/embed?post=' + encodeURIComponent(post.slug))
166 : '';
167%>
168<% if (_postAudio) { %>
169<meta property="og:video" content="<%= _e(_embedUrl) %>">
170<meta property="og:video:secure_url" content="<%= _e(_embedUrl) %>">
171<meta property="og:video:type" content="text/html">
172<meta property="og:video:width" content="480">
[98b7fdd]173<meta property="og:video:height" content="480">
[4c9c60b]174<% } %>
[7bc636b]175<% if (typeof post !== 'undefined' && post && post.published_at) { %>
176<meta property="article:published_time" content="<%= _e(post.published_at) %>">
177<% if (post.author_username) { %><meta property="article:author" content="<%= _e(post.author_username) %>"><% } %>
178<% } %>
179<% if (safeSite.facebook_app_id) { %><meta property="fb:app_id" content="<%= _e(safeSite.facebook_app_id) %>"><% } %>
180
181<!-- Twitter Cards -->
[4c9c60b]182<meta name="twitter:card" content="<%= _postAudio ? 'player' : (_socialImage ? 'summary_large_image' : 'summary') %>">
183<% if (_postAudio) { %>
184<meta name="twitter:player" content="<%= _e(_embedUrl) %>">
185<meta name="twitter:player:width" content="480">
[98b7fdd]186<meta name="twitter:player:height" content="480">
[4c9c60b]187<% } %>
[7bc636b]188<meta name="twitter:title" content="<%= _e(_socialTitle) %>">
189<meta name="twitter:description" content="<%= _e(_socialDescr) %>">
190<% if (_socialImage) { %><meta name="twitter:image" content="<%= _e(_socialImage) %>"><% } %>
191<% if (safeSite.twitter) { %><meta name="twitter:creator" content="<%= _e(safeSite.twitter) %>"><meta name="twitter:site" content="<%= _e(safeSite.twitter) %>"><% } %>
192
193<% if (_jsonLd) { %>
194<script type="application/ld+json"><%- JSON.stringify(_jsonLd) %></script>
195<% } %>
196
197<!-- Self-hosted fonts (privacy-first) -->
198<link rel="preload" href="/assets/fonts/literata-latin-opsz-normal.woff2" as="font" type="font/woff2" crossorigin>
199<link rel="preload" href="/assets/fonts/fraunces-latin-full-normal.woff2" as="font" type="font/woff2" crossorigin>
200
201<!-- v9 stylesheet (full palette system) -->
[3038fc9]202<link rel="stylesheet" href="/assets/css/style.css?v=62">
[a036251]203<script>
[76f0e61]204/* iOS safe-area, built by hand. env(safe-area-inset-top) resolves to 0 on this iOS in
205 BOTH Safari and the installed PWA (standalone), even with viewport-fit=cover, so the
206 masthead can't clear the camera. We measure env directly and, when it comes back empty
207 on a notched iPhone, fall back to a fixed inset (a bit larger in standalone for the
208 Dynamic Island). We set --ios-safe-top AND force the masthead padding inline — the
209 latter survives a stale cached stylesheet that lacks the var. Re-applied after htmx
210 chrome swaps (the top-nav is out-of-band swapped on navigation). */
[a036251]211(function(){
212 var ua = navigator.userAgent || '';
213 var isIOS = /iP(hone|od|ad)/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
214 if (!isIOS) return;
[76f0e61]215 var standalone = (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) || navigator.standalone === true;
216 function apply(){
[a036251]217 if (!document.body) return;
218 var p = document.createElement('div');
219 p.style.cssText = 'position:fixed;top:0;left:0;width:0;height:0;padding-top:env(safe-area-inset-top,0px);visibility:hidden;pointer-events:none';
220 document.body.appendChild(p);
[b8bbe77]221 var rawEnv = parseFloat(getComputedStyle(p).paddingTop) || 0;
[a036251]222 p.remove();
[b8bbe77]223 var i = rawEnv;
[9327a85]224 if (i < 20 && Math.max(screen.width, screen.height) >= 812) {
225 // Portrait: the island sits at the TOP → full inset (UNCHANGED: standalone?59:47).
226 // Landscape: the island moves to the SIDE, so the top inset is ~0 → no top padding
227 // (only the masthead's own base padding remains). env() can't tell us (returns 0),
228 // so we key off orientation directly.
229 i = (window.innerWidth > window.innerHeight) ? 0 : (standalone ? 59 : 47);
230 }
[a036251]231 document.documentElement.style.setProperty('--ios-safe-top', i + 'px');
[76f0e61]232 var mh = document.querySelector('.masthead');
[f6b2c68]233 var mhHidden = !mh || getComputedStyle(mh).display === 'none' || mh.offsetHeight === 0;
234 if (mhHidden) {
235 /* Mobile: the masthead is hidden (bottom-tab replaces it ≤767px) so it can't carry
236 the inset. Pad the body instead → the profile-header clears the island/notch. */
237 document.body.style.paddingTop = i + 'px';
238 if (mh) mh.style.paddingTop = '';
239 } else {
240 /* Desktop/landscape: the sticky masthead carries the inset in its own padding. */
241 document.body.style.paddingTop = '';
242 mh.style.paddingTop = 'calc(.55rem + ' + i + 'px)';
243 }
[a036251]244 }
[76f0e61]245 if (document.body) apply(); else document.addEventListener('DOMContentLoaded', apply);
246 document.addEventListener('htmx:afterSettle', apply);
247 window.addEventListener('orientationchange', function(){ setTimeout(apply, 250); });
[a036251]248})();
249</script>
[7bc636b]250
251<!-- Audio player styles: loaded on every page so the mini-player works
252 anywhere (admin previews, post embeds, etc). The player itself is
253 a singleton — see the script tag near </body>. -->
[903f10b]254<link rel="stylesheet" href="/assets/css/audio.css?v=11">
[4c9f29a]255<!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) in huisstijl. -->
[cb95343]256<link rel="stylesheet" href="/assets/css/embed.css?v=9">
[7bc636b]257
258<%- include('partials/shared-styles') %>
259
260<!-- v1 P55 — Inline the saved site accent. The base stylesheet only sets a
261 fallback (#c2410c orange) and palette blocks don't define --accent at
262 all, so without this override the saved accent never reaches the page.
263 :root + [data-palette] hits both unscoped and palette-scoped variants;
264 source-order wins on equal specificity, and this comes after style.css. -->
265<style id="pcms-site-accent">
266 :root,
267 [data-palette] {
268 --accent: <%= _e(safeAccent) %>;
269 --accent-soft: color-mix(in srgb, <%= _e(safeAccent) %> 80%, white);
270 --accent-tint: color-mix(in srgb, <%= _e(safeAccent) %> 12%, transparent);
271 }
272</style>
273
274<!-- Per-site custom CSS injection -->
275<% if (safeSite.custom_css) { %>
276<style id="pcms-custom-css"><%- safeSite.custom_css %></style>
277<% } %>
278
279<!-- Apply theme ASAP, before paint. Precedence (first match wins):
280 1. localStorage override (visitor toggled earlier on this browser)
281 2. Site default (theme_override + palette) — what new visitors see
282 3. Device prefers-color-scheme (only if site default is empty/auto)
283 4. 'dark' as last-ditch fallback
284 Note: PALETTE never has a localStorage layer anymore. There's no UI for
285 visitors to pick a palette, so any cached pcms-palette is stale data
286 from old code paths and gets cleaned up here. Site default always wins
287 for palette. -->
288<script>
289 (function() {
290 try {
291 var siteDefault = '<%= safeSite.theme_override || "" %>';
[9cc0f9f]292 var sitePalette = '<%= (typeof palette !== 'undefined' && palette) ? palette : (safeSite.palette || 'klonkt') %>';
[7bc636b]293
294 // One-time cleanup: drop the orphan pcms-palette key set by P43-P57
295 // bootstrap. After this it never re-appears because nothing writes it.
296 try { localStorage.removeItem('pcms-palette'); } catch(_) {}
297
298 // Theme: localStorage > site override > device pref > dark
299 var storedTheme = null;
300 try { storedTheme = localStorage.getItem('pcms-theme'); } catch(_) {}
301 var deviceDark = window.matchMedia &&
302 window.matchMedia('(prefers-color-scheme: dark)').matches;
303 var t = storedTheme
304 || siteDefault
305 || (deviceDark ? 'dark' : 'light');
306
307 // Palette: site default only.
308 document.documentElement.setAttribute('data-theme', t);
309 document.documentElement.setAttribute('data-palette', sitePalette);
310 } catch(e) {
311 document.documentElement.setAttribute('data-theme', 'dark');
312 }
313 })();
314</script>
315
316<!-- HTMX — bundled locally from node_modules at boot, zero third-party requests -->
317<script src="/assets/js/htmx.min.js"></script>
318
319<!-- Per-site custom <head> HTML (analytics, verification, etc.) -->
320<% if (safeSite.custom_head_html) { %>
321<%- safeSite.custom_head_html %>
322<% } %>
323</head>
324
[3c196f9]325<body class="<%= bodyClass || 'on-home' %> has-bottom-tab" data-feed-view="<%= _e(safeSite.feed_view_default || 'timeline') %>" data-grid-cols="3" data-site-base="<%= _e((typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '') %>">
[7bc636b]326
[8afbdd6]327<% if (typeof isViewer !== 'undefined' && isViewer) { %>
328 <div class="viewer-banner" role="status">
329 <span class="viewer-banner-ico" aria-hidden="true">👁️</span>
330 <span class="viewer-banner-text"><strong>Kijker-modus</strong> — je kunt alles bekijken, maar niets wijzigen.</span>
[640b39c]331 </div>
[8afbdd6]332 <style>
333 .viewer-banner {
334 position: sticky; top: 0; z-index: 60;
335 display: flex; align-items: center; justify-content: center; gap: 0.5rem;
336 padding: 0.5rem 1rem;
337 background: linear-gradient(90deg,
338 color-mix(in srgb, var(--accent) 88%, #000) 0%,
339 var(--accent) 100%);
340 color: #fff;
341 font-size: 0.85rem; line-height: 1.3;
342 box-shadow: 0 1px 6px color-mix(in srgb, var(--accent) 45%, transparent);
343 }
344 .viewer-banner-ico { font-size: 1rem; }
345 .viewer-banner-text strong { font-weight: 700; }
346 </style>
[640b39c]347<% } %>
348
[3cd1aaa]349<%# Site-chrome (topnav + profielkop + view-switcher) in één vaste slot #pcms-chrome.
350 Bij htmx-navigatie wordt dit slot out-of-band ververst (zie chrome.ejs +
351 render.js), zodat de kop ALTIJD bij de nieuwe pagina/artiest hoort terwijl de
352 audioplayer (los in document.body) blijft leven → geen verspringen. Op de
353 hub-landing is het slot leeg: de hero is daar de header. %>
354<%- include('partials/chrome') %>
[7bc636b]355
[85d9fda]356<%# Geen hx-history-elt: htmx' eigen history staat uit (zie de link-boost).
357 Back/forward wordt door onze popstate-listener gedaan, die de partial
358 her-fetcht (incl. correcte OOB-chrome). Met hx-history-elt + htmx-history
359 aan dumpte htmx de partial ongefilterd hier → dubbele kop. %>
360<main id="pcms-main" class="pcms-main">
[7bc636b]361 <div id="pcms-loading" class="pcms-loading" aria-hidden="true"></div>
362 <%- pageContent %>
363</main>
364
365<%- include('partials/footer') %>
366
[6224462]367<!-- Mobile bottom-tab navigation (auto-hidden ≥768px). Toont overal — óók op de
368 hub-landing (zodat mobiel altijd Home/Zoek/Inloggen heeft) — behalve op de
369 auth-focusschermen. -->
370<% if (!(typeof bodyClass === 'string' && bodyClass.indexOf('on-auth') >= 0)) { %>
[7bc636b]371<%- include('partials/bottom-tab') %>
[4c5169f]372<% } %>
[7bc636b]373
374<!-- Mobile profile sheet (auto-hidden ≥768px; only rendered when logged in) -->
375<% if (user) { %>
376<%- include('partials/profile-sheet') %>
377<% } %>
378
379<!-- Audio player: load on every page (admin + public) so window.pcmsAudioPlayer
380 is always available. The PCMS_SITE_TRACKS bootstrap is still gated on
381 enable_audio_player since it's a public-page concept (auto-discovered
[cf96890]382 tracks from rendered post embeds).
383
384 ?v=N — cache-buster: bump bij elke audio-player.js wijziging zodat
385 Cloudflare (max-age=1y) niet de oude versie blijft serveren. -->
[73cffc3]386<script src="/assets/js/audio-player.js?v=31"></script>
[4c9f29a]387<!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) via de echte
388 player-API's + gedeelde mutual-exclusion registry met de site-speler. -->
[cb95343]389<script src="/assets/js/embed-player.js?v=17" defer></script>
[7bc636b]390<% if (site && site.enable_audio_player && audioTracks && audioTracks.length > 0) { %>
391 <script>window.PCMS_SITE_TRACKS = <%- JSON.stringify(audioTracks) %>;</script>
392<% } %>
393
394<!-- Install-app button: detects platform + shows install instructions modal -->
[942028f]395<script src="/assets/js/install-app.js?v=2" defer></script>
[7bc636b]396
397<!-- Service Worker registration -->
398<script>
399 if ('serviceWorker' in navigator) {
400 navigator.serviceWorker.register('/sw.js').catch(() => {});
401 }
402</script>
403
404<!-- HTMX navigation: keep body class in sync with the swapped page.
405 The server emits HX-Trigger-After-Settle: { pcmsNav: { bodyClass } } via
406 renderPage() in middleware/render.js. Without this listener the body
407 class stays whatever the initial page-load set, so the profile-header
408 never collapses/expands when navigating home → post → home via HTMX. -->
409<script>
410(function() {
[441f5d6]411 // De page-context body-classes. Bij pcmsNav strippen we ze allemaal en zetten
412 // we opnieuw wat de server stuurde. 'on-auth' staat erbij zodat het login-
413 // focusscherm óók via htmx z'n styling krijgt (geen chrome, geen tab, audio op 0).
[da4387b]414 var PAGE_CLASSES = ['on-home','on-post','on-special','on-archive','on-search','on-admin','on-auth',
415 'on-shows','on-downloads','on-download','on-epk','on-linkbio','on-newsletter',
416 'on-tag','on-type','on-user','on-cirkel','on-hub','on-chat'];
[7bc636b]417
418 document.body.addEventListener('pcmsNav', function(ev) {
[a3e2f17]419 var d = ev.detail || {};
420 // Per-site accent + palette bijwerken (head wordt niet mee-geswapt bij htmx-nav,
421 // dus zonder dit erft een artiest de kleuren van de vorige pagina).
422 if (d.accent && /^#[0-9a-fA-F]{6}$/.test(d.accent)) {
423 var sa = document.getElementById('pcms-site-accent');
424 if (sa) {
425 sa.textContent =
426 ':root,[data-palette]{--accent:' + d.accent +
427 ';--accent-soft:color-mix(in srgb,' + d.accent + ' 80%,white)' +
428 ';--accent-tint:color-mix(in srgb,' + d.accent + ' 12%,transparent);}';
429 }
430 }
431 if (d.palette && /^[a-z0-9-]+$/i.test(d.palette)) {
432 document.documentElement.setAttribute('data-palette', d.palette);
433 }
434
435 var next = d.bodyClass;
[7bc636b]436 if (!next) return;
[441f5d6]437 // De server kan meerdere page-classes sturen ("on-special on-auth"). Strip
438 // alle bekende en zet ALLE meegestuurde page-classes terug (niet alleen de
439 // eerste) — anders mist 'on-auth' bij htmx-nav en blijft het login-scherm
440 // de chrome/tab van de vorige pagina houden.
441 var matched = String(next).split(/\s+/).filter(function(c) {
[7bc636b]442 return PAGE_CLASSES.indexOf(c) >= 0;
443 });
[441f5d6]444 if (!matched.length) return;
[7bc636b]445 PAGE_CLASSES.forEach(function(c) { document.body.classList.remove(c); });
[441f5d6]446 matched.forEach(function(c) { document.body.classList.add(c); });
[7bc636b]447 });
[6a2abb1]448
[85d9fda]449 // (Back/forward wordt afgehandeld door de popstate-listener in de link-boost
450 // hieronder — die her-fetcht de partial via htmx.ajax, wat de OOB-chrome +
451 // de pcmsNav-trigger (accent/palette/bodyClass) correct toepast. De vroegere
452 // htmx:historyRestore-handler is vervallen nu htmx-history uitstaat.)
[7bc636b]453})();
454</script>
455
456<!-- View switcher + grid-cols persistence (event delegation: works for switcher
457 elements rendered later by HTMX, e.g. when navigating back to home). -->
458<script>
459(function() {
460 var body = document.body;
461 // Restore feed view + grid cols from localStorage (overrides server default)
462 try {
463 var v = localStorage.getItem('pcms-feed-view');
464 if (v === 'timeline' || v === 'grid') body.dataset.feedView = v;
465 var c = parseInt(localStorage.getItem('pcms-grid-cols'), 10);
466 if (c === 2 || c === 3 || c === 4) body.dataset.gridCols = String(c);
467 } catch (e) {}
468
469 function syncAria() {
[1c6d61c]470 // Alleen op een feed-pagina hoort Tijdlijn/Grid 'actief' (wit) te zijn; op
471 // agenda/downloads/post/etc. beide grijs. Inline feed-check (FEED_PAGE_CLASSES
472 // staat verderop, maar deze functie draait al bij init).
473 var _feedC = ['on-home','on-tag','on-type','on-user','on-cirkel'];
474 var _onFeed = _feedC.some(function(c){ return body.classList.contains(c); });
[7bc636b]475 document.querySelectorAll('.view-switch-btn').forEach(function(b) {
[1c6d61c]476 b.setAttribute('aria-selected', (_onFeed && b.dataset.view === body.dataset.feedView) ? 'true' : 'false');
[7bc636b]477 });
478 document.querySelectorAll('.grid-cols-btn').forEach(function(b) {
479 b.classList.toggle('is-active', b.dataset.cols === body.dataset.gridCols);
480 });
481 }
482 syncAria();
[cf0de0c]483 // Re-sync after HTMX brings in new content (e.g. navigating back to home).
484 // pcmsNav vuurt ná de body-class-update (zie de pcmsNav-listener hierboven), dus
485 // dáár weet syncAria de juiste pagina-class — los van de afterSettle-timing.
486 // Een vertraagde herhaling wint eventuele resterende races (OOB-chrome-swap).
487 document.body.addEventListener('htmx:afterSettle', function(){ syncAria(); setTimeout(syncAria, 60); });
488 document.body.addEventListener('pcmsNav', function(){ syncAria(); setTimeout(syncAria, 60); });
[7bc636b]489
490 // Pages where the body actually has a feed to toggle. On these the
491 // click stays put — it just flips body[data-feed-view] and CSS does
492 // the rest. Anywhere else (post detail, account, search, auth) we
493 // navigate to home in the chosen view, so the switcher is never
494 // a dead control.
[ec2e358]495 // NB: 'on-archive' staat hier bewust NIET tussen — op het archief is er geen
496 // in-place timeline/grid-toggle; een klik op de switcher springt terug naar de
497 // feed in de gekozen weergave (zie de !isFeedPage()-tak hieronder).
498 var FEED_PAGE_CLASSES = ['on-home', 'on-tag', 'on-type', 'on-user', 'on-cirkel'];
[7bc636b]499 function isFeedPage() {
500 for (var i = 0; i < FEED_PAGE_CLASSES.length; i++) {
501 if (body.classList.contains(FEED_PAGE_CLASSES[i])) return true;
502 }
503 return false;
504 }
505
506 // Event delegation — single listener handles current and future buttons.
507 document.addEventListener('click', function(e) {
508 var sw = e.target.closest('.view-switch-btn');
509 if (sw) {
510 var view = sw.dataset.view;
511 body.dataset.feedView = view;
512 try { localStorage.setItem('pcms-feed-view', view); } catch(_) {}
513 syncAria();
514 // On non-feed pages the switcher acts as a navigation: take the
515 // user back to home in the chosen view. Use HTMX if available so
516 // the page transition matches the rest of the site's nav.
517 if (!isFeedPage()) {
[3c196f9]518 // Naar de SITE-home in de gekozen view (siteUrlBase), niet de globale '/'
519 // — in hub is '/' de hub-overview, niet de tijdlijn van deze artiest.
520 var base = body.dataset.siteBase || '';
[7bc636b]521 if (window.htmx) {
[3c196f9]522 window.htmx.ajax('GET', base + '/?partial=1', { target: '#pcms-main', swap: 'innerHTML' });
523 history.pushState({}, '', base + '/');
[7bc636b]524 } else {
[3c196f9]525 location.href = base + '/';
[7bc636b]526 }
527 }
528 return;
529 }
530 var gc = e.target.closest('.grid-cols-btn');
531 if (gc) {
532 body.dataset.gridCols = gc.dataset.cols;
533 try { localStorage.setItem('pcms-grid-cols', gc.dataset.cols); } catch(_) {}
534 syncAria();
535 }
536 });
537})();
538</script>
539
[79bba6e]540<!-- Globale link-boost: alle interne navigatie-links lopen via htmx in #pcms-main,
541 zodat de audioplayer (los in document.body) blijft spelen i.p.v. te verspringen
542 bij een full page-load. Werkt overal — Beheer, Account, posts, sites — zonder
543 elke link los htmx te maken. Links die écht een volledige load nodig hebben
544 (uitloggen/auth, downloads, feeds, media, assets, bestanden) worden overgeslagen,
545 net als links die al hun eigen hx-* hebben. -->
546<script>
547(function () {
548 if (!window.htmx) return;
[85d9fda]549 // htmx' EIGEN history-afhandeling volledig uitzetten. We doen back/forward zelf
550 // via de popstate-listener hieronder (htmx.ajax → verwerkt de OOB-chrome netjes).
551 // Lieten we htmx z'n gang gaan, dan herstelde 'ie #pcms-main door de partial
552 // (inclusief de <div id=pcms-chrome hx-swap-oob>) ONGEFILTERD in #pcms-main te
553 // dumpen → een tweede, geneste kop = de pagina dubbel. Eén mechanisme nu.
554 try { window.htmx.config.historyEnabled = false; } catch (_) {}
[79bba6e]555
556 function fullLoad(a, url) {
557 if (a.hasAttribute('download') || a.hasAttribute('data-full-load')) return true;
558 if (a.hasAttribute('hx-get') || a.hasAttribute('hx-post') || a.hasAttribute('hx-boost')) return true;
559 if (a.target && a.target !== '_self') return true;
560 if (a.getAttribute('rel') === 'external') return true;
561 var p = url.pathname;
[7990e00]562 // Sessie/redirect-acties → volledige navigatie (cookies, Google-redirect).
563 // Maar de auth-FORMULIERpagina's (/auth/admin, /auth/login, /auth/register,
564 // /auth/reset…) mogen wél via htmx, zodat de audiospeler blijft doorspelen
565 // i.p.v. te herstarten/verspringen bij een volledige page-load.
566 if (/^\/(logout|oauth)(?:\/|$)/.test(p)) return true;
567 if (/^\/auth\/(logout|google)(?:\/|$)/.test(p)) return true;
[79bba6e]568 // Feeds, PWA, service-worker, statics, media-streams, downloads.
569 if (/^\/(feed|atom|sitemap|manifest|robots|sw\.js|assets|media|audio|uploads)(?:\/|\.|$)/.test(p)) return true;
570 if (/\.[a-z0-9]{2,5}$/i.test(p)) return true; // bestandsextensie → laat de browser 't halen
571 return false;
572 }
573
574 var lastPath = location.pathname + location.search;
[389aa99]575 var navTimer = null;
576
577 // Eén plek voor alle programmatische navigatie-swaps. Annuleert eerst een nog
578 // lopende request op #pcms-main (anti-race: bij snel klikken/terug-gaan kan een
579 // trage oude response anders een nieuwe pagina overschrijven → "kale content").
580 function doNav(dest) {
581 try { window.htmx.trigger('#pcms-main', 'htmx:abort'); } catch (_) {}
582 window.htmx.ajax('GET', dest, { target: '#pcms-main', swap: 'innerHTML' });
583 }
[79bba6e]584
585 document.addEventListener('click', function (e) {
586 if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
587 var a = e.target.closest('a[href]');
588 if (!a) return;
589 var href = a.getAttribute('href');
590 if (!href || href.charAt(0) === '#') return;
591 var url; try { url = new URL(a.href, location.href); } catch (_) { return; }
592 if (url.origin !== location.origin) return;
593 if (fullLoad(a, url)) return;
594 e.preventDefault();
595 var dest = url.pathname + url.search;
596 if (dest !== lastPath) history.pushState({ b: 1 }, '', dest);
597 lastPath = dest;
[389aa99]598 if (navTimer) { clearTimeout(navTimer); navTimer = null; }
599 doNav(dest);
[79bba6e]600 try { window.scrollTo(0, 0); } catch (_) {}
601 });
602
603 window.addEventListener('popstate', function () {
604 var here = location.pathname + location.search;
605 if (here === lastPath) return;
606 lastPath = here;
[389aa99]607 // Debounce: bij heel snel/herhaald terug-vooruit niet elke tussenpagina ophalen,
608 // alleen de LAATSTE bestemming. Voorkomt overlappende swaps ("kale content").
609 if (navTimer) clearTimeout(navTimer);
610 navTimer = setTimeout(function () {
611 navTimer = null;
612 doNav(location.pathname + location.search);
613 }, 90);
[79bba6e]614 });
[6b8afb1]615
616 // Links MÉT eigen hx-get + hx-push-url (post-card/post-tile/topnav/…) lopen NIET
617 // via de boost hierboven, en hx-push-url is een no-op nu htmx-history uitstaat.
618 // Doe daarom de adresbalk-update hier zelf zodra htmx swapt. Programmatische
619 // htmx.ajax-calls (boost/popstate) hebben geen elt met hx-push-url → geen dubbel.
[9b3e12c]620 document.body.addEventListener('htmx:beforeRequest', function (evt) {
[6b8afb1]621 try {
[9b3e12c]622 var elt = evt.detail && evt.detail.elt; // het TRIGGERENDE element (de link)
623 if (!elt || !elt.closest) return;
624 var node = elt.closest('[hx-push-url]');
625 if (!node) return;
626 var u = node.getAttribute('hx-push-url');
[6b8afb1]627 if (!u || u === 'false') return;
[9b3e12c]628 if (u !== (location.pathname + location.search)) history.pushState({ b: 1 }, '', u);
[6b8afb1]629 lastPath = u;
630 } catch (_) {}
631 });
[1080d14]632
633 // Spring naar boven na ELKE navigatie-swap van #pcms-main. De boost hierboven
634 // scrollt al, maar links met hun eigen hx-get (post-nav Newer/Older, post-kaarten)
635 // lopen NIET via de boost → zonder dit blijf je op de oude scrollpositie hangen
636 // bij het openen van een gerelateerde/volgende post. Alleen #pcms-main, zodat
637 // in-page swaps (comments e.d.) en de OOB-chrome-swap niet meescrollen.
638 document.body.addEventListener('htmx:afterSwap', function (evt) {
639 var t = evt.detail && evt.detail.target;
640 if (t && t.id === 'pcms-main') { try { window.scrollTo(0, 0); } catch (_) {} }
641 });
[79bba6e]642})();
643</script>
644
[9ef3c56]645<!-- Mobiel toetsenbord vs. site-layout: zet body.kb-open zodra het toetsenbord
646 open is (visual viewport fors korter dan het venster) ÉN er een invoerveld
647 focus heeft. CSS verbergt dan de vaste onderbalken (bottom-tab + mini-speler)
648 zodat ze niet over het invoerveld zweven. -->
649<script>
650(function () {
651 var vv = window.visualViewport;
652 if (!vv) return;
653 function isField(el) {
654 if (!el) return false;
655 var t = el.tagName;
656 return t === 'INPUT' || t === 'TEXTAREA' || el.isContentEditable;
657 }
658 function update() {
659 var open = (window.innerHeight - vv.height) > 150 && isField(document.activeElement);
660 document.body.classList.toggle('kb-open', open);
661 }
662 vv.addEventListener('resize', update);
663 vv.addEventListener('scroll', update);
664 document.addEventListener('focusin', function () { setTimeout(update, 60); });
665 document.addEventListener('focusout', function () { setTimeout(update, 60); });
666})();
667</script>
668
[d188736]669<!-- Afbeeldingen lastiger op te slaan: rechtsklik-menu + slepen blokkeren op <img>.
670 Frictie, geen echte beveiliging (DevTools/screenshot blijven kunnen). -->
671<script>
672(function () {
673 document.addEventListener('contextmenu', function (e) {
674 if (e.target && e.target.tagName === 'IMG') e.preventDefault();
675 });
676 document.addEventListener('dragstart', function (e) {
677 if (e.target && e.target.tagName === 'IMG') e.preventDefault();
678 });
679})();
680</script>
681
[f3f43df]682<!-- Auto-resize: elk <textarea> groeit mee met de inhoud i.p.v. intern te scrollen
683 (scroll-binnen-scroll is verwarrend). Site-breed; ook na htmx-swaps. -->
684<script>
685(function () {
686 function autoSize(ta) {
687 if (!ta || ta.tagName !== 'TEXTAREA') return;
[8d054ca]688 // Skip hidden textareas (e.g. inside a closed <details> or an unopened reply
689 // box): measuring scrollHeight there yields a bad height that sticks as inline
690 // style and makes the field open huge. They get sized on focus once visible.
691 if (ta.offsetParent === null && ta.offsetHeight === 0) return;
[f3f43df]692 ta.style.height = 'auto';
[8d054ca]693 var maxH = parseFloat(getComputedStyle(ta).maxHeight);
694 var sh = ta.scrollHeight;
695 var h = (maxH && !isNaN(maxH)) ? Math.min(sh, maxH) : sh; // respect a CSS max-height
696 ta.style.height = h + 'px';
697 ta.style.overflowY = sh > h ? 'auto' : 'hidden';
[f3f43df]698 }
699 function sizeAll(root) {
700 (root || document).querySelectorAll('textarea').forEach(autoSize);
701 }
702 document.addEventListener('input', function (e) { autoSize(e.target); });
703 document.addEventListener('focusin', function (e) { autoSize(e.target); });
704 // Init + opnieuw na htmx-navigatie/partials.
705 sizeAll();
706 document.body.addEventListener('htmx:afterSettle', function () { sizeAll(); });
707 window.addEventListener('load', function () { sizeAll(); });
708})();
709</script>
710
[7bc636b]711<!-- PWA install prompt — show button when browser fires beforeinstallprompt -->
712<script>
713(function() {
714 var btn = document.getElementById('pwa-install-btn');
715 if (!btn) return;
716 var deferred = null;
717 window.addEventListener('beforeinstallprompt', function(e) {
718 e.preventDefault();
719 deferred = e;
720 btn.hidden = false;
721 });
722 btn.addEventListener('click', async function() {
723 if (!deferred) return;
724 btn.hidden = true;
725 deferred.prompt();
726 try { await deferred.userChoice; } catch(e) {}
727 deferred = null;
728 });
729 window.addEventListener('appinstalled', function() {
730 btn.hidden = true;
731 deferred = null;
732 });
733})();
734</script>
735
[837fc9c]736<!-- NSFW / sensitive content: click a veil/reveal to un-blur. Capture-phase so the
737 click reveals instead of following the card link or firing htmx navigation. -->
[a64d705]738<script>
739// Cover fade-in: a cover image that's still loading is hidden so the accent-gradient
740// placeholder behind it shows; it fades in once loaded. Cached/complete images stay
741// visible (no flash). Runs on load + htmx swaps.
742(function () {
743 if (window.__coverFadeWired) return; window.__coverFadeWired = true;
744 function scan(root) {
[600fbf3]745 (root || document).querySelectorAll('.grid-tile-img, .post-list-cover img, .tl-media-img img').forEach(function (img) {
[a64d705]746 if (img.dataset.fade) return; img.dataset.fade = '1';
747 if (img.complete && img.naturalWidth > 0) return; // already loaded → leave visible
748 img.classList.add('is-loading');
749 var done = function () { img.classList.remove('is-loading'); };
750 img.addEventListener('load', done, { once: true });
751 img.addEventListener('error', done, { once: true });
752 });
753 }
754 scan(document);
755 document.body.addEventListener('htmx:afterSettle', function (e) { scan(e.target); });
756})();
757</script>
758
[837fc9c]759<script>
760(function () {
761 if (window.__nsfwWired) return; window.__nsfwWired = true;
762 document.addEventListener('click', function (e) {
763 var hit = e.target.closest && e.target.closest('.nsfw-veil, .nsfw-reveal');
764 if (!hit) return;
765 e.preventDefault(); e.stopPropagation();
766 var box = hit.closest('.nsfw-media, .nsfw-gate');
767 if (box) box.classList.add('is-shown');
768 }, true);
769})();
770</script>
771
[f7d142f]772<script>
773// Delegated replacements for inline on* handlers, so the CSP needs no
774// script-src-attr 'unsafe-inline'. Document-level → also covers htmx-swapped content.
775(function () {
776 if (window.__pcmsHandlersWired) return; window.__pcmsHandlersWired = true;
777 // Confirm before submitting a form that carries data-confirm.
778 document.addEventListener('submit', function (e) {
779 var f = e.target;
780 if (f && f.dataset && f.dataset.confirm && !window.confirm(f.dataset.confirm)) e.preventDefault();
781 });
782 // Auto-submit a form / switch language when a <select> changes.
783 document.addEventListener('change', function (e) {
784 var el = e.target;
785 if (!el || !el.dataset) return;
786 if (el.dataset.autosubmit !== undefined && el.form) el.form.submit();
787 else if (el.dataset.langSwitch !== undefined) {
788 location.href = '/lang/' + encodeURIComponent(el.value) + '?r=' + encodeURIComponent(location.pathname + location.search);
789 }
790 });
791 // Misc click helpers (select-all in a field, history-back button).
792 document.addEventListener('click', function (e) {
793 var el = e.target.closest && e.target.closest('[data-selectall],[data-back]');
794 if (!el) return;
795 if (el.dataset.selectall !== undefined && el.select) el.select();
796 if (el.dataset.back !== undefined) { e.preventDefault(); history.back(); }
797 });
798 // Image fallback (the error event doesn't bubble → capture phase).
799 document.addEventListener('error', function (e) {
800 var el = e.target;
801 if (el && el.tagName === 'IMG' && el.dataset && el.dataset.fallback !== undefined && el.parentElement) {
802 el.parentElement.innerHTML = '<span class="pl-cover-empty">⚠️</span>';
803 }
804 }, true);
805})();
806</script>
807
[7bc636b]808<!-- Per-site custom footer HTML -->
809<% if (safeSite.custom_foot_html) { %>
810<%- safeSite.custom_foot_html %>
811<% } %>
812
813</body>
814</html>
Note: See TracBrowser for help on using the repository browser.