[object Object]

← back to 1890swallpaper

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

b66f9edad4b9c82ec0150fdd00e35ea610dd209e · 2026-06-01 15:21:39 -0700 · Steve

Files touched

Diff

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

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

diff --git a/public/index.html b/public/index.html
index 85e2914..b65e1db 100644
--- a/public/index.html
+++ b/public/index.html
@@ -1091,41 +1091,26 @@ loadGridPage();
 // 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 bg = document.getElementById('heroBg') || document.getElementById('cinemaBg');
-    if (!bg) return;
-    // RULE (Steve): a full-bleed hero MUST be high-res. The product master image
-    // is often too small and turns to mush when stretched edge-to-edge. So probe
-    // each candidate (rotating per visit) and only swap in one that's genuinely
-    // large; if none qualify, keep the crisp static /hero-bg.jpg already set in CSS.
-    const MIN_HERO_W = 2000;
-    const off = items.length ? (visits % items.length) : 0;
-    const ordered = items.slice(off).concat(items.slice(0, off));
-    (function tryNext(i){
-      if (i >= ordered.length) return; // none big enough → keep static hero-bg.jpg
-      const url = ordered[i].image_url.replace(/(_\d+x\d*)(\.(jpg|jpeg|png|webp|gif))(\?|$)/i, '$2$4');
-      const probe = new Image();
-      probe.onload = function(){
-        if (probe.naturalWidth >= MIN_HERO_W) bg.style.backgroundImage = "url('" + url + "')";
-        else tryNext(i + 1);
-      };
-      probe.onerror = function(){ tryNext(i + 1); };
-      probe.src = url;
-    })(0);
+    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);
 })();
 
 

← 3ed424b header name → domain name '1890s Wallpaper' (remove odd bran  ·  back to 1890swallpaper  ·  FIX: dw-header was injected inside a doc-comment (never ran) fed0973 →