| 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 : '#c2410c';
|
|---|
| 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|prutter|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 | const _socialImage = (typeof socialImage !== 'undefined' && socialImage)
|
|---|
| 60 | ? socialImage
|
|---|
| 61 | : (safeSite.og_image_default || safeSite.default_cover || '');
|
|---|
| 62 | const _ogType = isPostPage ? 'article' : 'website';
|
|---|
| 63 |
|
|---|
| 64 | // ── JSON-LD ───────────────────────────────────────────────────────
|
|---|
| 65 | const _publisher = {
|
|---|
| 66 | '@type': safeSite.schema_type === 'Organization' ? 'Organization' : 'Person',
|
|---|
| 67 | name: safeSite.publisher_name || _siteTitle,
|
|---|
| 68 | url: safeSite.publisher_url || (_canonical ? _canonical.split(/(?<=^[^/]*\/\/[^/]+)\//)[0] + '/' : null),
|
|---|
| 69 | };
|
|---|
| 70 | if (safeSite.publisher_logo) {
|
|---|
| 71 | _publisher.logo = { '@type': 'ImageObject', url: safeSite.publisher_logo };
|
|---|
| 72 | }
|
|---|
| 73 | let _jsonLd = null;
|
|---|
| 74 | if (typeof post !== 'undefined' && post && post.slug) {
|
|---|
| 75 | _jsonLd = {
|
|---|
| 76 | '@context': 'https://schema.org',
|
|---|
| 77 | '@type': (post.type === 'foto' || post.type === 'video') ? 'CreativeWork' : 'Article',
|
|---|
| 78 | headline: post.title || _siteTitle,
|
|---|
| 79 | description: _socialDescr,
|
|---|
| 80 | datePublished: post.published_at || post.created_at || new Date().toISOString(),
|
|---|
| 81 | dateModified: post.updated_at || post.published_at || new Date().toISOString(),
|
|---|
| 82 | publisher: _publisher,
|
|---|
| 83 | };
|
|---|
| 84 | if (_socialImage) _jsonLd.image = _socialImage;
|
|---|
| 85 | if (post.author_username) _jsonLd.author = { '@type': 'Person', name: post.author_username };
|
|---|
| 86 | if (Array.isArray(post.tags) && post.tags.length) _jsonLd.keywords = post.tags.join(', ');
|
|---|
| 87 | } else if (isHomePage) {
|
|---|
| 88 | _jsonLd = {
|
|---|
| 89 | '@context': 'https://schema.org',
|
|---|
| 90 | '@type': 'WebSite',
|
|---|
| 91 | name: _siteTitle,
|
|---|
| 92 | description: safeSite.description || safeSite.default_description || '',
|
|---|
| 93 | publisher: _publisher,
|
|---|
| 94 | };
|
|---|
| 95 | }
|
|---|
| 96 | %><!DOCTYPE html>
|
|---|
| 97 | <html lang="<%= _e(lang) %>" data-palette="<%= _e(safeSite.palette || 'sage') %>">
|
|---|
| 98 | <head>
|
|---|
| 99 | <meta charset="utf-8">
|
|---|
| 100 | <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
|---|
| 101 | <meta name="color-scheme" content="dark light">
|
|---|
| 102 |
|
|---|
| 103 | <title><%= _finalTitle %></title>
|
|---|
| 104 | <meta name="description" content="<%= _e(_socialDescr) %>">
|
|---|
| 105 | <meta name="theme-color" content="<%= _e(safeAccent) %>">
|
|---|
| 106 | <meta name="robots" content="<%= _shouldIndex ? 'index,follow' : 'noindex,nofollow' %>">
|
|---|
| 107 | <% if (safeSite.author) { %><meta name="author" content="<%= _e(safeSite.author) %>"><% } %>
|
|---|
| 108 | <% if (_canonical) { %><link rel="canonical" href="<%= _e(_canonical) %>"><% } %>
|
|---|
| 109 |
|
|---|
| 110 | <!-- Search-engine verification -->
|
|---|
| 111 | <% if (safeSite.google_verification) { %><meta name="google-site-verification" content="<%= _e(safeSite.google_verification) %>"><% } %>
|
|---|
| 112 | <% if (safeSite.bing_verification) { %><meta name="msvalidate.01" content="<%= _e(safeSite.bing_verification) %>"><% } %>
|
|---|
| 113 | <% if (safeSite.pinterest_verification) { %><meta name="p:domain_verify" content="<%= _e(safeSite.pinterest_verification) %>"><% } %>
|
|---|
| 114 | <% if (safeSite.yandex_verification) { %><meta name="yandex-verification" content="<%= _e(safeSite.yandex_verification) %>"><% } %>
|
|---|
| 115 |
|
|---|
| 116 | <!-- Feed autodiscovery -->
|
|---|
| 117 | <% if (site) { %>
|
|---|
| 118 | <link rel="alternate" type="application/rss+xml" title="<%= _e(_siteTitle) %> — RSS" href="<%= _e(safeUrlBase + '/feed.xml') %>">
|
|---|
| 119 | <link rel="alternate" type="application/atom+xml" title="<%= _e(_siteTitle) %> — Atom" href="<%= _e(safeUrlBase + '/atom.xml') %>">
|
|---|
| 120 | <% } %>
|
|---|
| 121 |
|
|---|
| 122 | <!-- PWA -->
|
|---|
| 123 | <link rel="manifest" href="<%= _e(safeUrlBase + '/manifest.webmanifest') %>">
|
|---|
| 124 | <meta name="mobile-web-app-capable" content="yes">
|
|---|
| 125 | <meta name="apple-mobile-web-app-capable" content="yes">
|
|---|
| 126 | <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|---|
| 127 | <meta name="apple-mobile-web-app-title" content="<%= _e(_siteTitle.slice(0, 16)) %>">
|
|---|
| 128 | <link rel="apple-touch-icon" href="<%= _e(safeSite.profile_photo || '/favicon.ico') %>">
|
|---|
| 129 | <link rel="icon" type="image/svg+xml" href="/favicon.svg?v=sf">
|
|---|
| 130 | <link rel="alternate icon" href="/favicon.ico?v=sf">
|
|---|
| 131 |
|
|---|
| 132 | <!-- OpenGraph -->
|
|---|
| 133 | <meta property="og:type" content="<%= _ogType %>">
|
|---|
| 134 | <meta property="og:title" content="<%= _e(_socialTitle) %>">
|
|---|
| 135 | <meta property="og:description" content="<%= _e(_socialDescr) %>">
|
|---|
| 136 | <meta property="og:site_name" content="<%= _e(_siteTitle) %>">
|
|---|
| 137 | <meta property="og:locale" content="<%= _e(ogLocale) %>">
|
|---|
| 138 | <% if (_socialImage) { %>
|
|---|
| 139 | <meta property="og:image" content="<%= _e(_socialImage) %>">
|
|---|
| 140 | <meta property="og:image:alt" content="<%= _e(_socialTitle) %>">
|
|---|
| 141 | <% } %>
|
|---|
| 142 | <% if (_canonical) { %><meta property="og:url" content="<%= _e(_canonical) %>"><% } %>
|
|---|
| 143 | <% if (typeof post !== 'undefined' && post && post.published_at) { %>
|
|---|
| 144 | <meta property="article:published_time" content="<%= _e(post.published_at) %>">
|
|---|
| 145 | <% if (post.author_username) { %><meta property="article:author" content="<%= _e(post.author_username) %>"><% } %>
|
|---|
| 146 | <% } %>
|
|---|
| 147 | <% if (safeSite.facebook_app_id) { %><meta property="fb:app_id" content="<%= _e(safeSite.facebook_app_id) %>"><% } %>
|
|---|
| 148 |
|
|---|
| 149 | <!-- Twitter Cards -->
|
|---|
| 150 | <meta name="twitter:card" content="<%= _socialImage ? 'summary_large_image' : 'summary' %>">
|
|---|
| 151 | <meta name="twitter:title" content="<%= _e(_socialTitle) %>">
|
|---|
| 152 | <meta name="twitter:description" content="<%= _e(_socialDescr) %>">
|
|---|
| 153 | <% if (_socialImage) { %><meta name="twitter:image" content="<%= _e(_socialImage) %>"><% } %>
|
|---|
| 154 | <% if (safeSite.twitter) { %><meta name="twitter:creator" content="<%= _e(safeSite.twitter) %>"><meta name="twitter:site" content="<%= _e(safeSite.twitter) %>"><% } %>
|
|---|
| 155 |
|
|---|
| 156 | <% if (_jsonLd) { %>
|
|---|
| 157 | <script type="application/ld+json"><%- JSON.stringify(_jsonLd) %></script>
|
|---|
| 158 | <% } %>
|
|---|
| 159 |
|
|---|
| 160 | <!-- Self-hosted fonts (privacy-first) -->
|
|---|
| 161 | <link rel="preload" href="/assets/fonts/literata-latin-opsz-normal.woff2" as="font" type="font/woff2" crossorigin>
|
|---|
| 162 | <link rel="preload" href="/assets/fonts/fraunces-latin-full-normal.woff2" as="font" type="font/woff2" crossorigin>
|
|---|
| 163 |
|
|---|
| 164 | <!-- v9 stylesheet (full palette system) -->
|
|---|
| 165 | <link rel="stylesheet" href="/assets/css/style.css?v=18">
|
|---|
| 166 |
|
|---|
| 167 | <!-- Audio player styles: loaded on every page so the mini-player works
|
|---|
| 168 | anywhere (admin previews, post embeds, etc). The player itself is
|
|---|
| 169 | a singleton — see the script tag near </body>. -->
|
|---|
| 170 | <link rel="stylesheet" href="/assets/css/audio.css?v=7">
|
|---|
| 171 | <!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) in huisstijl. -->
|
|---|
| 172 | <link rel="stylesheet" href="/assets/css/embed.css?v=8">
|
|---|
| 173 |
|
|---|
| 174 | <%- include('partials/shared-styles') %>
|
|---|
| 175 |
|
|---|
| 176 | <!-- v1 P55 — Inline the saved site accent. The base stylesheet only sets a
|
|---|
| 177 | fallback (#c2410c orange) and palette blocks don't define --accent at
|
|---|
| 178 | all, so without this override the saved accent never reaches the page.
|
|---|
| 179 | :root + [data-palette] hits both unscoped and palette-scoped variants;
|
|---|
| 180 | source-order wins on equal specificity, and this comes after style.css. -->
|
|---|
| 181 | <style id="pcms-site-accent">
|
|---|
| 182 | :root,
|
|---|
| 183 | [data-palette] {
|
|---|
| 184 | --accent: <%= _e(safeAccent) %>;
|
|---|
| 185 | --accent-soft: color-mix(in srgb, <%= _e(safeAccent) %> 80%, white);
|
|---|
| 186 | --accent-tint: color-mix(in srgb, <%= _e(safeAccent) %> 12%, transparent);
|
|---|
| 187 | }
|
|---|
| 188 | </style>
|
|---|
| 189 |
|
|---|
| 190 | <!-- Per-site custom CSS injection -->
|
|---|
| 191 | <% if (safeSite.custom_css) { %>
|
|---|
| 192 | <style id="pcms-custom-css"><%- safeSite.custom_css %></style>
|
|---|
| 193 | <% } %>
|
|---|
| 194 |
|
|---|
| 195 | <!-- Apply theme ASAP, before paint. Precedence (first match wins):
|
|---|
| 196 | 1. localStorage override (visitor toggled earlier on this browser)
|
|---|
| 197 | 2. Site default (theme_override + palette) — what new visitors see
|
|---|
| 198 | 3. Device prefers-color-scheme (only if site default is empty/auto)
|
|---|
| 199 | 4. 'dark' as last-ditch fallback
|
|---|
| 200 | Note: PALETTE never has a localStorage layer anymore. There's no UI for
|
|---|
| 201 | visitors to pick a palette, so any cached pcms-palette is stale data
|
|---|
| 202 | from old code paths and gets cleaned up here. Site default always wins
|
|---|
| 203 | for palette. -->
|
|---|
| 204 | <script>
|
|---|
| 205 | (function() {
|
|---|
| 206 | try {
|
|---|
| 207 | var siteDefault = '<%= safeSite.theme_override || "" %>';
|
|---|
| 208 | var sitePalette = '<%= safeSite.palette || "sage" %>';
|
|---|
| 209 |
|
|---|
| 210 | // One-time cleanup: drop the orphan pcms-palette key set by P43-P57
|
|---|
| 211 | // bootstrap. After this it never re-appears because nothing writes it.
|
|---|
| 212 | try { localStorage.removeItem('pcms-palette'); } catch(_) {}
|
|---|
| 213 |
|
|---|
| 214 | // Theme: localStorage > site override > device pref > dark
|
|---|
| 215 | var storedTheme = null;
|
|---|
| 216 | try { storedTheme = localStorage.getItem('pcms-theme'); } catch(_) {}
|
|---|
| 217 | var deviceDark = window.matchMedia &&
|
|---|
| 218 | window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|---|
| 219 | var t = storedTheme
|
|---|
| 220 | || siteDefault
|
|---|
| 221 | || (deviceDark ? 'dark' : 'light');
|
|---|
| 222 |
|
|---|
| 223 | // Palette: site default only.
|
|---|
| 224 | document.documentElement.setAttribute('data-theme', t);
|
|---|
| 225 | document.documentElement.setAttribute('data-palette', sitePalette);
|
|---|
| 226 | } catch(e) {
|
|---|
| 227 | document.documentElement.setAttribute('data-theme', 'dark');
|
|---|
| 228 | }
|
|---|
| 229 | })();
|
|---|
| 230 | </script>
|
|---|
| 231 |
|
|---|
| 232 | <!-- HTMX — bundled locally from node_modules at boot, zero third-party requests -->
|
|---|
| 233 | <script src="/assets/js/htmx.min.js"></script>
|
|---|
| 234 |
|
|---|
| 235 | <!-- Per-site custom <head> HTML (analytics, verification, etc.) -->
|
|---|
| 236 | <% if (safeSite.custom_head_html) { %>
|
|---|
| 237 | <%- safeSite.custom_head_html %>
|
|---|
| 238 | <% } %>
|
|---|
| 239 | </head>
|
|---|
| 240 |
|
|---|
| 241 | <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 : '') %>">
|
|---|
| 242 |
|
|---|
| 243 | <% if (typeof isViewer !== 'undefined' && isViewer) { %>
|
|---|
| 244 | <div class="viewer-banner" role="status">
|
|---|
| 245 | <span class="viewer-banner-ico" aria-hidden="true">👁️</span>
|
|---|
| 246 | <span class="viewer-banner-text"><strong>Kijker-modus</strong> — je kunt alles bekijken, maar niets wijzigen.</span>
|
|---|
| 247 | </div>
|
|---|
| 248 | <style>
|
|---|
| 249 | .viewer-banner {
|
|---|
| 250 | position: sticky; top: 0; z-index: 60;
|
|---|
| 251 | display: flex; align-items: center; justify-content: center; gap: 0.5rem;
|
|---|
| 252 | padding: 0.5rem 1rem;
|
|---|
| 253 | background: linear-gradient(90deg,
|
|---|
| 254 | color-mix(in srgb, var(--accent) 88%, #000) 0%,
|
|---|
| 255 | var(--accent) 100%);
|
|---|
| 256 | color: #fff;
|
|---|
| 257 | font-size: 0.85rem; line-height: 1.3;
|
|---|
| 258 | box-shadow: 0 1px 6px color-mix(in srgb, var(--accent) 45%, transparent);
|
|---|
| 259 | }
|
|---|
| 260 | .viewer-banner-ico { font-size: 1rem; }
|
|---|
| 261 | .viewer-banner-text strong { font-weight: 700; }
|
|---|
| 262 | </style>
|
|---|
| 263 | <% } %>
|
|---|
| 264 |
|
|---|
| 265 | <%# Site-chrome (topnav + profielkop + view-switcher) in één vaste slot #pcms-chrome.
|
|---|
| 266 | Bij htmx-navigatie wordt dit slot out-of-band ververst (zie chrome.ejs +
|
|---|
| 267 | render.js), zodat de kop ALTIJD bij de nieuwe pagina/artiest hoort terwijl de
|
|---|
| 268 | audioplayer (los in document.body) blijft leven → geen verspringen. Op de
|
|---|
| 269 | hub-landing is het slot leeg: de hero is daar de header. %>
|
|---|
| 270 | <%- include('partials/chrome') %>
|
|---|
| 271 |
|
|---|
| 272 | <%# Geen hx-history-elt: htmx' eigen history staat uit (zie de link-boost).
|
|---|
| 273 | Back/forward wordt door onze popstate-listener gedaan, die de partial
|
|---|
| 274 | her-fetcht (incl. correcte OOB-chrome). Met hx-history-elt + htmx-history
|
|---|
| 275 | aan dumpte htmx de partial ongefilterd hier → dubbele kop. %>
|
|---|
| 276 | <main id="pcms-main" class="pcms-main">
|
|---|
| 277 | <div id="pcms-loading" class="pcms-loading" aria-hidden="true"></div>
|
|---|
| 278 | <%- pageContent %>
|
|---|
| 279 | </main>
|
|---|
| 280 |
|
|---|
| 281 | <%- include('partials/footer') %>
|
|---|
| 282 |
|
|---|
| 283 | <!-- Mobile bottom-tab navigation (auto-hidden ≥768px). Toont overal — óók op de
|
|---|
| 284 | hub-landing (zodat mobiel altijd Home/Zoek/Inloggen heeft) — behalve op de
|
|---|
| 285 | auth-focusschermen. -->
|
|---|
| 286 | <% if (!(typeof bodyClass === 'string' && bodyClass.indexOf('on-auth') >= 0)) { %>
|
|---|
| 287 | <%- include('partials/bottom-tab') %>
|
|---|
| 288 | <% } %>
|
|---|
| 289 |
|
|---|
| 290 | <!-- Mobile profile sheet (auto-hidden ≥768px; only rendered when logged in) -->
|
|---|
| 291 | <% if (user) { %>
|
|---|
| 292 | <%- include('partials/profile-sheet') %>
|
|---|
| 293 | <% } %>
|
|---|
| 294 |
|
|---|
| 295 | <!-- Audio player: load on every page (admin + public) so window.pcmsAudioPlayer
|
|---|
| 296 | is always available. The PCMS_SITE_TRACKS bootstrap is still gated on
|
|---|
| 297 | enable_audio_player since it's a public-page concept (auto-discovered
|
|---|
| 298 | tracks from rendered post embeds).
|
|---|
| 299 |
|
|---|
| 300 | ?v=N — cache-buster: bump bij elke audio-player.js wijziging zodat
|
|---|
| 301 | Cloudflare (max-age=1y) niet de oude versie blijft serveren. -->
|
|---|
| 302 | <script src="/assets/js/audio-player.js?v=28"></script>
|
|---|
| 303 | <!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) via de echte
|
|---|
| 304 | player-API's + gedeelde mutual-exclusion registry met de site-speler. -->
|
|---|
| 305 | <script src="/assets/js/embed-player.js?v=16" defer></script>
|
|---|
| 306 | <% if (site && site.enable_audio_player && audioTracks && audioTracks.length > 0) { %>
|
|---|
| 307 | <script>window.PCMS_SITE_TRACKS = <%- JSON.stringify(audioTracks) %>;</script>
|
|---|
| 308 | <% } %>
|
|---|
| 309 |
|
|---|
| 310 | <!-- Install-app button: detects platform + shows install instructions modal -->
|
|---|
| 311 | <script src="/assets/js/install-app.js?v=2" defer></script>
|
|---|
| 312 |
|
|---|
| 313 | <!-- Service Worker registration -->
|
|---|
| 314 | <script>
|
|---|
| 315 | if ('serviceWorker' in navigator) {
|
|---|
| 316 | navigator.serviceWorker.register('/sw.js').catch(() => {});
|
|---|
| 317 | }
|
|---|
| 318 | </script>
|
|---|
| 319 |
|
|---|
| 320 | <!-- HTMX navigation: keep body class in sync with the swapped page.
|
|---|
| 321 | The server emits HX-Trigger-After-Settle: { pcmsNav: { bodyClass } } via
|
|---|
| 322 | renderPage() in middleware/render.js. Without this listener the body
|
|---|
| 323 | class stays whatever the initial page-load set, so the profile-header
|
|---|
| 324 | never collapses/expands when navigating home → post → home via HTMX. -->
|
|---|
| 325 | <script>
|
|---|
| 326 | (function() {
|
|---|
| 327 | // De page-context body-classes. Bij pcmsNav strippen we ze allemaal en zetten
|
|---|
| 328 | // we opnieuw wat de server stuurde. 'on-auth' staat erbij zodat het login-
|
|---|
| 329 | // focusscherm óók via htmx z'n styling krijgt (geen chrome, geen tab, audio op 0).
|
|---|
| 330 | var PAGE_CLASSES = ['on-home','on-post','on-special','on-archive','on-search','on-admin','on-auth'];
|
|---|
| 331 |
|
|---|
| 332 | document.body.addEventListener('pcmsNav', function(ev) {
|
|---|
| 333 | var d = ev.detail || {};
|
|---|
| 334 | // Per-site accent + palette bijwerken (head wordt niet mee-geswapt bij htmx-nav,
|
|---|
| 335 | // dus zonder dit erft een artiest de kleuren van de vorige pagina).
|
|---|
| 336 | if (d.accent && /^#[0-9a-fA-F]{6}$/.test(d.accent)) {
|
|---|
| 337 | var sa = document.getElementById('pcms-site-accent');
|
|---|
| 338 | if (sa) {
|
|---|
| 339 | sa.textContent =
|
|---|
| 340 | ':root,[data-palette]{--accent:' + d.accent +
|
|---|
| 341 | ';--accent-soft:color-mix(in srgb,' + d.accent + ' 80%,white)' +
|
|---|
| 342 | ';--accent-tint:color-mix(in srgb,' + d.accent + ' 12%,transparent);}';
|
|---|
| 343 | }
|
|---|
| 344 | }
|
|---|
| 345 | if (d.palette && /^[a-z0-9-]+$/i.test(d.palette)) {
|
|---|
| 346 | document.documentElement.setAttribute('data-palette', d.palette);
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | var next = d.bodyClass;
|
|---|
| 350 | if (!next) return;
|
|---|
| 351 | // De server kan meerdere page-classes sturen ("on-special on-auth"). Strip
|
|---|
| 352 | // alle bekende en zet ALLE meegestuurde page-classes terug (niet alleen de
|
|---|
| 353 | // eerste) — anders mist 'on-auth' bij htmx-nav en blijft het login-scherm
|
|---|
| 354 | // de chrome/tab van de vorige pagina houden.
|
|---|
| 355 | var matched = String(next).split(/\s+/).filter(function(c) {
|
|---|
| 356 | return PAGE_CLASSES.indexOf(c) >= 0;
|
|---|
| 357 | });
|
|---|
| 358 | if (!matched.length) return;
|
|---|
| 359 | PAGE_CLASSES.forEach(function(c) { document.body.classList.remove(c); });
|
|---|
| 360 | matched.forEach(function(c) { document.body.classList.add(c); });
|
|---|
| 361 | });
|
|---|
| 362 |
|
|---|
| 363 | // (Back/forward wordt afgehandeld door de popstate-listener in de link-boost
|
|---|
| 364 | // hieronder — die her-fetcht de partial via htmx.ajax, wat de OOB-chrome +
|
|---|
| 365 | // de pcmsNav-trigger (accent/palette/bodyClass) correct toepast. De vroegere
|
|---|
| 366 | // htmx:historyRestore-handler is vervallen nu htmx-history uitstaat.)
|
|---|
| 367 | })();
|
|---|
| 368 | </script>
|
|---|
| 369 |
|
|---|
| 370 | <!-- View switcher + grid-cols persistence (event delegation: works for switcher
|
|---|
| 371 | elements rendered later by HTMX, e.g. when navigating back to home). -->
|
|---|
| 372 | <script>
|
|---|
| 373 | (function() {
|
|---|
| 374 | var body = document.body;
|
|---|
| 375 | // Restore feed view + grid cols from localStorage (overrides server default)
|
|---|
| 376 | try {
|
|---|
| 377 | var v = localStorage.getItem('pcms-feed-view');
|
|---|
| 378 | if (v === 'timeline' || v === 'grid') body.dataset.feedView = v;
|
|---|
| 379 | var c = parseInt(localStorage.getItem('pcms-grid-cols'), 10);
|
|---|
| 380 | if (c === 2 || c === 3 || c === 4) body.dataset.gridCols = String(c);
|
|---|
| 381 | } catch (e) {}
|
|---|
| 382 |
|
|---|
| 383 | function syncAria() {
|
|---|
| 384 | document.querySelectorAll('.view-switch-btn').forEach(function(b) {
|
|---|
| 385 | b.setAttribute('aria-selected', b.dataset.view === body.dataset.feedView ? 'true' : 'false');
|
|---|
| 386 | });
|
|---|
| 387 | document.querySelectorAll('.grid-cols-btn').forEach(function(b) {
|
|---|
| 388 | b.classList.toggle('is-active', b.dataset.cols === body.dataset.gridCols);
|
|---|
| 389 | });
|
|---|
| 390 | }
|
|---|
| 391 | syncAria();
|
|---|
| 392 | // Re-sync after HTMX brings in new content (e.g. navigating back to home)
|
|---|
| 393 | document.body.addEventListener('htmx:afterSettle', syncAria);
|
|---|
| 394 |
|
|---|
| 395 | // Pages where the body actually has a feed to toggle. On these the
|
|---|
| 396 | // click stays put — it just flips body[data-feed-view] and CSS does
|
|---|
| 397 | // the rest. Anywhere else (post detail, account, search, auth) we
|
|---|
| 398 | // navigate to home in the chosen view, so the switcher is never
|
|---|
| 399 | // a dead control.
|
|---|
| 400 | // NB: 'on-archive' staat hier bewust NIET tussen — op het archief is er geen
|
|---|
| 401 | // in-place timeline/grid-toggle; een klik op de switcher springt terug naar de
|
|---|
| 402 | // feed in de gekozen weergave (zie de !isFeedPage()-tak hieronder).
|
|---|
| 403 | var FEED_PAGE_CLASSES = ['on-home', 'on-tag', 'on-type', 'on-user', 'on-cirkel'];
|
|---|
| 404 | function isFeedPage() {
|
|---|
| 405 | for (var i = 0; i < FEED_PAGE_CLASSES.length; i++) {
|
|---|
| 406 | if (body.classList.contains(FEED_PAGE_CLASSES[i])) return true;
|
|---|
| 407 | }
|
|---|
| 408 | return false;
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 | // Event delegation — single listener handles current and future buttons.
|
|---|
| 412 | document.addEventListener('click', function(e) {
|
|---|
| 413 | var sw = e.target.closest('.view-switch-btn');
|
|---|
| 414 | if (sw) {
|
|---|
| 415 | var view = sw.dataset.view;
|
|---|
| 416 | body.dataset.feedView = view;
|
|---|
| 417 | try { localStorage.setItem('pcms-feed-view', view); } catch(_) {}
|
|---|
| 418 | syncAria();
|
|---|
| 419 | // On non-feed pages the switcher acts as a navigation: take the
|
|---|
| 420 | // user back to home in the chosen view. Use HTMX if available so
|
|---|
| 421 | // the page transition matches the rest of the site's nav.
|
|---|
| 422 | if (!isFeedPage()) {
|
|---|
| 423 | // Naar de SITE-home in de gekozen view (siteUrlBase), niet de globale '/'
|
|---|
| 424 | // — in hub is '/' de hub-overview, niet de tijdlijn van deze artiest.
|
|---|
| 425 | var base = body.dataset.siteBase || '';
|
|---|
| 426 | if (window.htmx) {
|
|---|
| 427 | window.htmx.ajax('GET', base + '/?partial=1', { target: '#pcms-main', swap: 'innerHTML' });
|
|---|
| 428 | history.pushState({}, '', base + '/');
|
|---|
| 429 | } else {
|
|---|
| 430 | location.href = base + '/';
|
|---|
| 431 | }
|
|---|
| 432 | }
|
|---|
| 433 | return;
|
|---|
| 434 | }
|
|---|
| 435 | var gc = e.target.closest('.grid-cols-btn');
|
|---|
| 436 | if (gc) {
|
|---|
| 437 | body.dataset.gridCols = gc.dataset.cols;
|
|---|
| 438 | try { localStorage.setItem('pcms-grid-cols', gc.dataset.cols); } catch(_) {}
|
|---|
| 439 | syncAria();
|
|---|
| 440 | }
|
|---|
| 441 | });
|
|---|
| 442 | })();
|
|---|
| 443 | </script>
|
|---|
| 444 |
|
|---|
| 445 | <!-- Globale link-boost: alle interne navigatie-links lopen via htmx in #pcms-main,
|
|---|
| 446 | zodat de audioplayer (los in document.body) blijft spelen i.p.v. te verspringen
|
|---|
| 447 | bij een full page-load. Werkt overal — Beheer, Account, posts, sites — zonder
|
|---|
| 448 | elke link los htmx te maken. Links die écht een volledige load nodig hebben
|
|---|
| 449 | (uitloggen/auth, downloads, feeds, media, assets, bestanden) worden overgeslagen,
|
|---|
| 450 | net als links die al hun eigen hx-* hebben. -->
|
|---|
| 451 | <script>
|
|---|
| 452 | (function () {
|
|---|
| 453 | if (!window.htmx) return;
|
|---|
| 454 | // htmx' EIGEN history-afhandeling volledig uitzetten. We doen back/forward zelf
|
|---|
| 455 | // via de popstate-listener hieronder (htmx.ajax → verwerkt de OOB-chrome netjes).
|
|---|
| 456 | // Lieten we htmx z'n gang gaan, dan herstelde 'ie #pcms-main door de partial
|
|---|
| 457 | // (inclusief de <div id=pcms-chrome hx-swap-oob>) ONGEFILTERD in #pcms-main te
|
|---|
| 458 | // dumpen → een tweede, geneste kop = de pagina dubbel. Eén mechanisme nu.
|
|---|
| 459 | try { window.htmx.config.historyEnabled = false; } catch (_) {}
|
|---|
| 460 |
|
|---|
| 461 | function fullLoad(a, url) {
|
|---|
| 462 | if (a.hasAttribute('download') || a.hasAttribute('data-full-load')) return true;
|
|---|
| 463 | if (a.hasAttribute('hx-get') || a.hasAttribute('hx-post') || a.hasAttribute('hx-boost')) return true;
|
|---|
| 464 | if (a.target && a.target !== '_self') return true;
|
|---|
| 465 | if (a.getAttribute('rel') === 'external') return true;
|
|---|
| 466 | var p = url.pathname;
|
|---|
| 467 | // Sessie/redirect-acties → volledige navigatie (cookies, Google-redirect).
|
|---|
| 468 | // Maar de auth-FORMULIERpagina's (/auth/admin, /auth/login, /auth/register,
|
|---|
| 469 | // /auth/reset…) mogen wél via htmx, zodat de audiospeler blijft doorspelen
|
|---|
| 470 | // i.p.v. te herstarten/verspringen bij een volledige page-load.
|
|---|
| 471 | if (/^\/(logout|oauth)(?:\/|$)/.test(p)) return true;
|
|---|
| 472 | if (/^\/auth\/(logout|google)(?:\/|$)/.test(p)) return true;
|
|---|
| 473 | // Feeds, PWA, service-worker, statics, media-streams, downloads.
|
|---|
| 474 | if (/^\/(feed|atom|sitemap|manifest|robots|sw\.js|assets|media|audio|uploads)(?:\/|\.|$)/.test(p)) return true;
|
|---|
| 475 | if (/\.[a-z0-9]{2,5}$/i.test(p)) return true; // bestandsextensie → laat de browser 't halen
|
|---|
| 476 | return false;
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | var lastPath = location.pathname + location.search;
|
|---|
| 480 | var navTimer = null;
|
|---|
| 481 |
|
|---|
| 482 | // Eén plek voor alle programmatische navigatie-swaps. Annuleert eerst een nog
|
|---|
| 483 | // lopende request op #pcms-main (anti-race: bij snel klikken/terug-gaan kan een
|
|---|
| 484 | // trage oude response anders een nieuwe pagina overschrijven → "kale content").
|
|---|
| 485 | function doNav(dest) {
|
|---|
| 486 | try { window.htmx.trigger('#pcms-main', 'htmx:abort'); } catch (_) {}
|
|---|
| 487 | window.htmx.ajax('GET', dest, { target: '#pcms-main', swap: 'innerHTML' });
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | document.addEventListener('click', function (e) {
|
|---|
| 491 | if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|---|
| 492 | var a = e.target.closest('a[href]');
|
|---|
| 493 | if (!a) return;
|
|---|
| 494 | var href = a.getAttribute('href');
|
|---|
| 495 | if (!href || href.charAt(0) === '#') return;
|
|---|
| 496 | var url; try { url = new URL(a.href, location.href); } catch (_) { return; }
|
|---|
| 497 | if (url.origin !== location.origin) return;
|
|---|
| 498 | if (fullLoad(a, url)) return;
|
|---|
| 499 | e.preventDefault();
|
|---|
| 500 | var dest = url.pathname + url.search;
|
|---|
| 501 | if (dest !== lastPath) history.pushState({ b: 1 }, '', dest);
|
|---|
| 502 | lastPath = dest;
|
|---|
| 503 | if (navTimer) { clearTimeout(navTimer); navTimer = null; }
|
|---|
| 504 | doNav(dest);
|
|---|
| 505 | try { window.scrollTo(0, 0); } catch (_) {}
|
|---|
| 506 | });
|
|---|
| 507 |
|
|---|
| 508 | window.addEventListener('popstate', function () {
|
|---|
| 509 | var here = location.pathname + location.search;
|
|---|
| 510 | if (here === lastPath) return;
|
|---|
| 511 | lastPath = here;
|
|---|
| 512 | // Debounce: bij heel snel/herhaald terug-vooruit niet elke tussenpagina ophalen,
|
|---|
| 513 | // alleen de LAATSTE bestemming. Voorkomt overlappende swaps ("kale content").
|
|---|
| 514 | if (navTimer) clearTimeout(navTimer);
|
|---|
| 515 | navTimer = setTimeout(function () {
|
|---|
| 516 | navTimer = null;
|
|---|
| 517 | doNav(location.pathname + location.search);
|
|---|
| 518 | }, 90);
|
|---|
| 519 | });
|
|---|
| 520 |
|
|---|
| 521 | // Links MÉT eigen hx-get + hx-push-url (post-card/post-tile/topnav/…) lopen NIET
|
|---|
| 522 | // via de boost hierboven, en hx-push-url is een no-op nu htmx-history uitstaat.
|
|---|
| 523 | // Doe daarom de adresbalk-update hier zelf zodra htmx swapt. Programmatische
|
|---|
| 524 | // htmx.ajax-calls (boost/popstate) hebben geen elt met hx-push-url → geen dubbel.
|
|---|
| 525 | document.body.addEventListener('htmx:beforeRequest', function (evt) {
|
|---|
| 526 | try {
|
|---|
| 527 | var elt = evt.detail && evt.detail.elt; // het TRIGGERENDE element (de link)
|
|---|
| 528 | if (!elt || !elt.closest) return;
|
|---|
| 529 | var node = elt.closest('[hx-push-url]');
|
|---|
| 530 | if (!node) return;
|
|---|
| 531 | var u = node.getAttribute('hx-push-url');
|
|---|
| 532 | if (!u || u === 'false') return;
|
|---|
| 533 | if (u !== (location.pathname + location.search)) history.pushState({ b: 1 }, '', u);
|
|---|
| 534 | lastPath = u;
|
|---|
| 535 | } catch (_) {}
|
|---|
| 536 | });
|
|---|
| 537 |
|
|---|
| 538 | // Spring naar boven na ELKE navigatie-swap van #pcms-main. De boost hierboven
|
|---|
| 539 | // scrollt al, maar links met hun eigen hx-get (post-nav Newer/Older, post-kaarten)
|
|---|
| 540 | // lopen NIET via de boost → zonder dit blijf je op de oude scrollpositie hangen
|
|---|
| 541 | // bij het openen van een gerelateerde/volgende post. Alleen #pcms-main, zodat
|
|---|
| 542 | // in-page swaps (comments e.d.) en de OOB-chrome-swap niet meescrollen.
|
|---|
| 543 | document.body.addEventListener('htmx:afterSwap', function (evt) {
|
|---|
| 544 | var t = evt.detail && evt.detail.target;
|
|---|
| 545 | if (t && t.id === 'pcms-main') { try { window.scrollTo(0, 0); } catch (_) {} }
|
|---|
| 546 | });
|
|---|
| 547 | })();
|
|---|
| 548 | </script>
|
|---|
| 549 |
|
|---|
| 550 | <!-- Mobiel toetsenbord vs. site-layout: zet body.kb-open zodra het toetsenbord
|
|---|
| 551 | open is (visual viewport fors korter dan het venster) ÉN er een invoerveld
|
|---|
| 552 | focus heeft. CSS verbergt dan de vaste onderbalken (bottom-tab + mini-speler)
|
|---|
| 553 | zodat ze niet over het invoerveld zweven. -->
|
|---|
| 554 | <script>
|
|---|
| 555 | (function () {
|
|---|
| 556 | var vv = window.visualViewport;
|
|---|
| 557 | if (!vv) return;
|
|---|
| 558 | function isField(el) {
|
|---|
| 559 | if (!el) return false;
|
|---|
| 560 | var t = el.tagName;
|
|---|
| 561 | return t === 'INPUT' || t === 'TEXTAREA' || el.isContentEditable;
|
|---|
| 562 | }
|
|---|
| 563 | function update() {
|
|---|
| 564 | var open = (window.innerHeight - vv.height) > 150 && isField(document.activeElement);
|
|---|
| 565 | document.body.classList.toggle('kb-open', open);
|
|---|
| 566 | }
|
|---|
| 567 | vv.addEventListener('resize', update);
|
|---|
| 568 | vv.addEventListener('scroll', update);
|
|---|
| 569 | document.addEventListener('focusin', function () { setTimeout(update, 60); });
|
|---|
| 570 | document.addEventListener('focusout', function () { setTimeout(update, 60); });
|
|---|
| 571 | })();
|
|---|
| 572 | </script>
|
|---|
| 573 |
|
|---|
| 574 | <!-- Afbeeldingen lastiger op te slaan: rechtsklik-menu + slepen blokkeren op <img>.
|
|---|
| 575 | Frictie, geen echte beveiliging (DevTools/screenshot blijven kunnen). -->
|
|---|
| 576 | <script>
|
|---|
| 577 | (function () {
|
|---|
| 578 | document.addEventListener('contextmenu', function (e) {
|
|---|
| 579 | if (e.target && e.target.tagName === 'IMG') e.preventDefault();
|
|---|
| 580 | });
|
|---|
| 581 | document.addEventListener('dragstart', function (e) {
|
|---|
| 582 | if (e.target && e.target.tagName === 'IMG') e.preventDefault();
|
|---|
| 583 | });
|
|---|
| 584 | })();
|
|---|
| 585 | </script>
|
|---|
| 586 |
|
|---|
| 587 | <!-- Auto-resize: elk <textarea> groeit mee met de inhoud i.p.v. intern te scrollen
|
|---|
| 588 | (scroll-binnen-scroll is verwarrend). Site-breed; ook na htmx-swaps. -->
|
|---|
| 589 | <script>
|
|---|
| 590 | (function () {
|
|---|
| 591 | function autoSize(ta) {
|
|---|
| 592 | if (!ta || ta.tagName !== 'TEXTAREA') return;
|
|---|
| 593 | ta.style.overflowY = 'hidden';
|
|---|
| 594 | ta.style.height = 'auto';
|
|---|
| 595 | ta.style.height = ta.scrollHeight + 'px';
|
|---|
| 596 | }
|
|---|
| 597 | function sizeAll(root) {
|
|---|
| 598 | (root || document).querySelectorAll('textarea').forEach(autoSize);
|
|---|
| 599 | }
|
|---|
| 600 | document.addEventListener('input', function (e) { autoSize(e.target); });
|
|---|
| 601 | document.addEventListener('focusin', function (e) { autoSize(e.target); });
|
|---|
| 602 | // Init + opnieuw na htmx-navigatie/partials.
|
|---|
| 603 | sizeAll();
|
|---|
| 604 | document.body.addEventListener('htmx:afterSettle', function () { sizeAll(); });
|
|---|
| 605 | window.addEventListener('load', function () { sizeAll(); });
|
|---|
| 606 | })();
|
|---|
| 607 | </script>
|
|---|
| 608 |
|
|---|
| 609 | <!-- PWA install prompt — show button when browser fires beforeinstallprompt -->
|
|---|
| 610 | <script>
|
|---|
| 611 | (function() {
|
|---|
| 612 | var btn = document.getElementById('pwa-install-btn');
|
|---|
| 613 | if (!btn) return;
|
|---|
| 614 | var deferred = null;
|
|---|
| 615 | window.addEventListener('beforeinstallprompt', function(e) {
|
|---|
| 616 | e.preventDefault();
|
|---|
| 617 | deferred = e;
|
|---|
| 618 | btn.hidden = false;
|
|---|
| 619 | });
|
|---|
| 620 | btn.addEventListener('click', async function() {
|
|---|
| 621 | if (!deferred) return;
|
|---|
| 622 | btn.hidden = true;
|
|---|
| 623 | deferred.prompt();
|
|---|
| 624 | try { await deferred.userChoice; } catch(e) {}
|
|---|
| 625 | deferred = null;
|
|---|
| 626 | });
|
|---|
| 627 | window.addEventListener('appinstalled', function() {
|
|---|
| 628 | btn.hidden = true;
|
|---|
| 629 | deferred = null;
|
|---|
| 630 | });
|
|---|
| 631 | })();
|
|---|
| 632 | </script>
|
|---|
| 633 |
|
|---|
| 634 | <!-- Per-site custom footer HTML -->
|
|---|
| 635 | <% if (safeSite.custom_foot_html) { %>
|
|---|
| 636 | <%- safeSite.custom_foot_html %>
|
|---|
| 637 | <% } %>
|
|---|
| 638 |
|
|---|
| 639 | </body>
|
|---|
| 640 | </html>
|
|---|