[object Object]

← back to 1920swallpaper

1920swallpaper: rails fire again — wire to matcher + per-site railSynonyms mapping curated rail names to real tag vocab

5c0ea08709d679b2372335ee2d5757cbff5fc72f · 2026-06-11 09:37:05 -0700 · SteveStudio2

Files touched

Diff

commit 5c0ea08709d679b2372335ee2d5757cbff5fc72f
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date:   Thu Jun 11 09:37:05 2026 -0700

    1920swallpaper: rails fire again — wire to matcher + per-site railSynonyms mapping curated rail names to real tag vocab
---
 server.js        | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
 site.config.json | 30 ++++++++++++++++++++++++++++--
 2 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/server.js b/server.js
index 0bc784b..fc8fdee 100644
--- a/server.js
+++ b/server.js
@@ -23,6 +23,47 @@ if (ADMIN_ENABLED) {
 const siteCfg = JSON.parse(fs.readFileSync(path.join(__dirname, 'site.config.json'), 'utf8'));
 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). Naive
+// p.aesthetic === key matching collapses rails when the field is sparse — the
+// richer signal lives in `tags` + per-site railSynonyms. Prefer the shared
+// matcher on dev; fall back to a self-contained copy on prod.
+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;
+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;
@@ -176,7 +217,7 @@ function filterProducts(query, skip) {
     const needle = String(q).toLowerCase();
     list = list.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.tags || []).some(t => String(t).toLowerCase().includes(needle)));
   }
-  if (skip !== 'aesthetic' && aesthetic && aesthetic !== 'all') list = list.filter(p => p.aesthetic === aesthetic);
+  if (skip !== 'aesthetic' && aesthetic && aesthetic !== 'all') list = list.filter(p => productInRail(p, aesthetic, RAIL_SYN));
   // SWEEP-A1: tag filter — sub-bucket rails on the homepage call /api/products?tag=<name>
   if (skip !== 'tag' && tag) {
     const wanted = String(tag).toLowerCase();
@@ -199,12 +240,8 @@ 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 });
+  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) => {
diff --git a/site.config.json b/site.config.json
index cccba52..4582518 100644
--- a/site.config.json
+++ b/site.config.json
@@ -16,5 +16,31 @@
     "jazz",
     "egyptian-revival",
     "flapper"
-  ]
-}
\ No newline at end of file
+  ],
+  "railSynonyms": {
+    "metallic": [
+      "gold",
+      "silver",
+      "bronze",
+      "brass",
+      "gilded",
+      "chrome",
+      "pewter"
+    ],
+    "jazz": [
+      "glamorous",
+      "sophisticated",
+      "modern"
+    ],
+    "egyptian-revival": [
+      "fretwork",
+      "geometric",
+      "abstract"
+    ],
+    "flapper": [
+      "glamorous",
+      "gold",
+      "sophisticated"
+    ]
+  }
+}

← f240a61 step2 vendor-leak fix: dual-key /sample resolver + handle_di  ·  back to 1920swallpaper  ·  fix: safeImg allow same-origin /img/ proxy urls (vendor-neut 9f939f4 →