[object Object]

← back to Retrowalls

hero: rotate curated room-setting pool (hero-pool.json), guard >=1400px, no swatch blur

4c2a8610ada7ebfc24d736ef32cc5e334416cbb5 · 2026-06-01 15:21:14 -0700 · Steve

Files touched

Diff

commit 4c2a8610ada7ebfc24d736ef32cc5e334416cbb5
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon Jun 1 15:21:14 2026 -0700

    hero: rotate curated room-setting pool (hero-pool.json), guard >=1400px, no swatch blur
---
 public/index.html | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/public/index.html b/public/index.html
index bc9b145..7e4d23d 100644
--- a/public/index.html
+++ b/public/index.html
@@ -1337,26 +1337,26 @@ document.addEventListener('DOMContentLoaded', function(){ try { renderRailSectio
 // takes the freshest 20, picks one per visit via localStorage counter.
 // Falls back to static /hero-bg.jpg on any error.
 (async function rotateHero() {
+  const bg = document.getElementById('heroBg') || document.getElementById('cinemaBg');
+  if (!bg) return;
+  let pool = [];
   try {
-    const r = await fetch('/api/products?limit=100');
-    if (!r.ok) return;
-    const d = await r.json();
-    const items = (d.items || [])
-      .filter(p => p && p.image_url && /^https:\/\/(?:cdn\.shopify\.com|designerwallcoverings\.com)\//.test(p.image_url))
-      .sort((a,b) => String(b.created_at || '').localeCompare(String(a.created_at || '')))
-      .slice(0, 20);
-    if (!items.length) return;
-    let visits = 0;
-    try {
-      visits = parseInt(localStorage.getItem('hero_visits') || '0', 10) || 0;
-      localStorage.setItem('hero_visits', String(visits + 1));
-    } catch(e) {}
-    const pick = items[visits % items.length];
-    // Strip _NxN size suffix to get the largest CDN variant
-    const url = pick.image_url.replace(/(_\d+x\d*)(\.(jpg|jpeg|png|webp|gif))(\?|$)/i, '$2$4');
-    const bg = document.getElementById('heroBg') || document.getElementById('cinemaBg');
-    if (bg) bg.style.backgroundImage = "url('" + url + "')";
+    const r = await fetch('/hero-pool.json', { cache: 'no-store' });
+    if (r.ok) { const j = await r.json(); pool = Array.isArray(j) ? j : (j.images || []); }
   } catch (e) {}
+  pool = (pool || []).filter(u => typeof u === 'string' && /^https?:\/\/|^\//.test(u));
+  if (!pool.length) return;                       // no curated pool -> keep sharp static hero
+  let visits = 0;
+  try { visits = parseInt(localStorage.getItem('hero_visits') || '0', 10) || 0; localStorage.setItem('hero_visits', String(visits + 1)); } catch (e) {}
+  const start = visits % pool.length;
+  (function tryAt(i) {
+    if (i >= pool.length) return;                 // none qualified -> static hero stays
+    const url = pool[(start + i) % pool.length];
+    const probe = new Image();
+    probe.onload = () => { if (probe.naturalWidth >= 1400) bg.style.backgroundImage = "url('" + url + "')"; else tryAt(i + 1); };
+    probe.onerror = () => tryAt(i + 1);
+    probe.src = url;
+  })(0);
 })();
 
 

← 58219f9 homepage: retire redundant corner-nav.js (ns-header hamburge  ·  back to Retrowalls  ·  admin: add dw-theme-nav 20-theme navigator (upper-right, adm 286f53e →