diff options
| author | Ken D'Ambrosio <ken@jots.org> | 2026-05-11 18:35:57 +0000 |
|---|---|---|
| committer | Ken D'Ambrosio <ken@jots.org> | 2026-05-11 18:35:57 +0000 |
| commit | 723a9bc34c30ddb0decedd9efe64af5b91b71541 (patch) | |
| tree | 0b246547a46fa0e932968ce83bf86700b30e94e4 /public/js | |
| parent | c19b0854543abd5d05e0f1c0615c45464c169d29 (diff) | |
Fix OG image previews: use ?photo= param so server can set correct og:imagev1.0
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'public/js')
| -rw-r--r-- | public/js/album.js | 18 |
1 files changed, 11 insertions, 7 deletions
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); } }); |
