← back to Chinoiseriewallpaper
chinoiseriewallpaper: rails fire again — wire sliders + grid filter to aesthetic-OR-tags matcher (prod-safe try-require + inline fallback)
140fac5bb6dcf79f416f4745de102e36a01ef438 · 2026-06-11 09:23:35 -0700 · Steve Abrams
Files touched
Diff
commit 140fac5bb6dcf79f416f4745de102e36a01ef438
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu Jun 11 09:23:35 2026 -0700
chinoiseriewallpaper: rails fire again — wire sliders + grid filter to aesthetic-OR-tags matcher (prod-safe try-require + inline fallback)
---
server.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 50 insertions(+), 11 deletions(-)
diff --git a/server.js b/server.js
index ff29d9e..172ee24 100644
--- a/server.js
+++ b/server.js
@@ -34,6 +34,51 @@ const siteCfg = JSON.parse(fs.readFileSync(path.join(__dirname, 'site.config.jso
const SITE_SLUG = siteCfg.slug || path.basename(__dirname);
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: "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) {} }
+
// Catalog now lives in dw_unified.microsite_products — populated async at
// startup (see bottom of file). Falls back to data/products.json if PG is down.
let DATA_RAW = [];
@@ -232,7 +277,7 @@ function filterProducts(list, { q, aesthetic } = {}, skip) {
);
}
if (aesthetic && aesthetic !== 'all' && skip !== 'aesthetic') {
- list = list.filter(p => p.aesthetic === aesthetic);
+ list = list.filter(p => productInRail(p, aesthetic, RAIL_SYN));
}
return list;
}
@@ -260,12 +305,8 @@ app.get('/api/products', (req, res) => {
// ── API — sliders ──────────────────────────────────────────────────────────
app.get('/api/sliders', (req, res) => {
- const out = [];
- for (const a of SITE_RAILS) {
- const items = PRODUCTS_PRE.filter(p => p.aesthetic === a).slice(0, 12);
- if (items.length >= 4) out.push({ aesthetic: a, items: decorateColors(items) });
- }
- res.json({ rails: out });
+ const rails = buildRails(PRODUCTS_PRE, SITE_RAILS, { synonyms: RAIL_SYN });
+ res.json({ rails: rails.map(r => ({ aesthetic: r.aesthetic, items: r.items })) });
});
// ── API — facets ───────────────────────────────────────────────────────────
@@ -275,10 +316,8 @@ app.get('/api/sliders', (req, res) => {
// totals after a search). `total` is the fully-filtered count.
app.get('/api/facets', (req, res) => {
const { q, aesthetic } = req.query;
- const aesthetics = {};
- for (const p of filterProducts(PRODUCTS_PRE, { q, aesthetic }, 'aesthetic')) {
- aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
- }
+ const filtered = filterProducts(PRODUCTS_PRE, { q, aesthetic }, 'aesthetic');
+ const aesthetics = railFacets(filtered, SITE_RAILS, RAIL_SYN);
const total = filterProducts(PRODUCTS_PRE, { q, aesthetic }).length;
res.json({ aesthetics, total });
});
← c4fe98a step2 vendor-leak fix: dual-key /sample resolver + handle_di
·
back to Chinoiseriewallpaper
·
banner: wire universal promo-banner require above express.st 58a57ae →