[object Object]

← back to Silkwallpaper

silkwallpaper: rails fire again — wire sliders/grid/facets to aesthetic-OR-tags matcher

e719916870e5cdb4a1b250b61835f2bf04777fc4 · 2026-06-11 09:12:14 -0700 · Steve Abrams

All 986 products carry the degenerate aesthetic 'all', so the naive
p.aesthetic===key matching collapsed every rail to empty and made the
?aesthetic= grid filter return nothing. /api/sliders, /api/products, and
/api/facets now use rail-match (aesthetic OR tags + hybrid share gate),
prod-safe via try-require with a self-contained inline fallback for the
static-only Kamatera path. Verified on real data: 6/6 rails fire (532-889
items), aesthetic=silk grid 0->410, facet counts honest, aesthetic=all=986.

Files touched

Diff

commit e719916870e5cdb4a1b250b61835f2bf04777fc4
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu Jun 11 09:12:14 2026 -0700

    silkwallpaper: rails fire again — wire sliders/grid/facets to aesthetic-OR-tags matcher
    
    All 986 products carry the degenerate aesthetic 'all', so the naive
    p.aesthetic===key matching collapsed every rail to empty and made the
    ?aesthetic= grid filter return nothing. /api/sliders, /api/products, and
    /api/facets now use rail-match (aesthetic OR tags + hybrid share gate),
    prod-safe via try-require with a self-contained inline fallback for the
    static-only Kamatera path. Verified on real data: 6/6 rails fire (532-889
    items), aesthetic=silk grid 0->410, facet counts honest, aesthetic=all=986.
---
 server.js | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 57 insertions(+), 13 deletions(-)

diff --git a/server.js b/server.js
index ae83fcd..7d58993 100644
--- a/server.js
+++ b/server.js
@@ -24,6 +24,51 @@ const siteCfg = JSON.parse(fs.readFileSync(path.join(__dirname, 'site.config.jso
 const SITE_SLUG = siteCfg.slug || __SITE;
 const SITE_RAILS = Array.isArray(siteCfg.rails) ? siteCfg.rails : [];
 
+// Read-time rail membership: a product belongs to a rail if its `aesthetic` OR
+// any `tag` equals the rail key (or a declared synonym). Sister-site catalogs
+// have a degenerate `aesthetic` (here: 986/986 "all"), so naive
+// `p.aesthetic === key` matching collapses every rail to empty — the richer
+// signal lives in `tags`. Prefer the shared matcher on dev; fall back to a
+// self-contained copy on prod where the _shared/ tree isn't deployed.
+let railMatch;
+try {
+  railMatch = require('../_shared/rail-match');
+} catch (e) {
+  const norm = s => String(s == null ? '' : s).trim().toLowerCase();
+  const productInRail = (p, key, syn) => {
+    const vals = [norm(key)].concat((syn && Array.isArray(syn[key]) ? syn[key] : []).map(norm));
+    if (vals.includes(norm(p && p.aesthetic))) return true;
+    const tags = p && Array.isArray(p.tags) ? p.tags : [];
+    return tags.some(t => vals.includes(norm(t)));
+  };
+  railMatch = {
+    productInRail,
+    buildRails(products, railKeys, opts) {
+      opts = opts || {}; const syn = opts.synonyms || null;
+      const minShare = opts.minShare != null ? opts.minShare : 0.08;
+      const minItems = opts.minItems != null ? opts.minItems : 4;
+      const perRail = opts.perRail != null ? opts.perRail : 12;
+      const maxShare = opts.maxShare != null ? opts.maxShare : 0.99;
+      const list = Array.isArray(products) ? products : []; const N = list.length || 1; const out = [];
+      for (const key of (railKeys || [])) {
+        const m = list.filter(p => productInRail(p, key, syn)); const c = m.length;
+        if (c >= minItems && c / N >= minShare && c / N <= maxShare) out.push({ key, aesthetic: key, count: c, items: m.slice(0, perRail) });
+      }
+      return out;
+    },
+    railFacets(products, railKeys, syn) {
+      const list = Array.isArray(products) ? products : []; const f = {};
+      for (const key of (railKeys || [])) f[key] = list.filter(p => productInRail(p, key, syn || null)).length;
+      return f;
+    }
+  };
+}
+const { productInRail, buildRails, railFacets } = railMatch;
+// Synonyms come from the site's own config (prod-safe); the shared default map
+// is a dev-only convenience when _shared/ is present.
+let RAIL_SYN = siteCfg.railSynonyms || {};
+if (!siteCfg.railSynonyms) { try { RAIL_SYN = require('../_shared/rail-synonyms.json'); } catch (e) {} }
+
 function isJunk(p) {
   if (!p.image_url || !p.image_url.trim()) return true;
   if (!p.handle && !p.sku) return true;
@@ -171,7 +216,7 @@ app.get('/api/products', (req, res) => {
     const needle = q.toLowerCase();
     list = list.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.tags || []).some(t => t.toLowerCase().includes(needle)));
   }
-  if (aesthetic && aesthetic !== 'all') list = list.filter(p => p.aesthetic === aesthetic);
+  if (aesthetic && aesthetic !== 'all') list = list.filter(p => productInRail(p, aesthetic, RAIL_SYN));
   if (vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
   list = sortProducts(list, sort);
   const total = list.length;
@@ -182,12 +227,10 @@ app.get('/api/products', (req, res) => {
 });
 
 app.get('/api/sliders', (req, res) => {
-  const out = [];
-  for (const a of SITE_RAILS) {
-    const items = PRODUCTS_NICHE.filter(p => p.aesthetic === a).slice(0, 12);
-    if (items.length >= 4) out.push({ aesthetic: a, items });
-  }
-  res.json({ rails: out });
+  // Multi-membership rails via aesthetic-OR-tags + hybrid share gate (was naive
+  // p.aesthetic === a, which collapsed to empty on the degenerate aesthetic).
+  const rails = buildRails(PRODUCTS_NICHE, SITE_RAILS, { synonyms: RAIL_SYN });
+  res.json({ rails: rails.map(r => ({ aesthetic: r.aesthetic, items: r.items })) });
 });
 
 app.get('/api/facets', (req, res) => {
@@ -200,12 +243,13 @@ app.get('/api/facets', (req, res) => {
     (p.title || '').toLowerCase().includes(q) ||
     (p.tags || []).some(t => String(t).toLowerCase().includes(q))
   );
-  if (aesthetic && aesthetic !== 'all') filtered = filtered.filter(p => p.aesthetic === aesthetic);
-  const aesthetics = {}; const vendors = {};
-  for (const p of filtered) {
-    aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
-    vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
-  }
+  if (aesthetic && aesthetic !== 'all') filtered = filtered.filter(p => productInRail(p, aesthetic, RAIL_SYN));
+  // Aesthetic facet counts mirror rail membership (drill-down: each rail counted
+  // over the set narrowed by the other active facets), not the degenerate
+  // p.aesthetic field. Keeps chip counts honest against the rails + grid.
+  const aesthetics = railFacets(filtered, SITE_RAILS, RAIL_SYN);
+  const vendors = {};
+  for (const p of filtered) vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
   res.json({ aesthetics, vendors, total: filtered.length });
 });
 

← cc78024 step2 vendor-leak fix: dual-key /sample resolver + handle_di  ·  back to Silkwallpaper  ·  Recompute aesthetic from tags via classifyAesthetic (was deg 8f30065 →