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