From 723a9bc34c30ddb0decedd9efe64af5b91b71541 Mon Sep 17 00:00:00 2001 From: Ken D'Ambrosio Date: Mon, 11 May 2026 18:35:57 +0000 Subject: Fix OG image previews: use ?photo= param so server can set correct og:image Co-Authored-By: Claude Sonnet 4.6 --- public/js/album.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'public/js/album.js') diff --git a/public/js/album.js b/public/js/album.js index d83cb5f..a2301c9 100644 --- a/public/js/album.js +++ b/public/js/album.js @@ -18,7 +18,10 @@ function closeLightbox() { const el = document.getElementById(id); el.pause && el.pause(); }); - history.replaceState(null, '', location.pathname + location.search); + const closeUrl = new URL(location.href); + closeUrl.searchParams.delete('photo'); + const closeQs = closeUrl.searchParams.toString(); + history.replaceState(null, '', closeUrl.pathname + (closeQs ? '?' + closeQs : '')); } function lbNav(delta) { @@ -78,8 +81,10 @@ function renderLightbox() { dl.href = e.src; dl.download = e.name; - // Update URL hash so the address bar is the shareable link - history.replaceState(null, '', location.pathname + location.search + '#photo=' + encodeURIComponent(e.name)); + // Update URL so the address bar is the shareable link + const photoUrl = new URL(location.href); + photoUrl.searchParams.set('photo', e.name); + history.replaceState(null, '', photoUrl.pathname + photoUrl.search); } function lbCopyLink() { @@ -107,10 +112,9 @@ function lbKey(ev) { // Restore lightbox from URL hash on page load window.addEventListener('DOMContentLoaded', () => { - const m = location.hash.match(/^#photo=(.+)$/); - if (m) { - const name = decodeURIComponent(m[1]); - const idx = ENTRIES.findIndex(e => e.name === name); + const photoName = new URLSearchParams(location.search).get('photo'); + if (photoName) { + const idx = ENTRIES.findIndex(e => e.name === photoName); if (idx >= 0) openLightbox(idx); } }); -- cgit v1.2.3