← back to Carmelwallpapers
carmelwallpapers: rails fire again — wire sliders + grid filter to aesthetic-OR-tags matcher (hand edit; site uses hardcoded RAIL_ORDER scaffold)
69a8d9252cc251306b19b90840e425fd1297c884 · 2026-06-11 09:32:12 -0700 · Steve Abrams
Files touched
Diff
commit 69a8d9252cc251306b19b90840e425fd1297c884
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu Jun 11 09:32:12 2026 -0700
carmelwallpapers: rails fire again — wire sliders + grid filter to aesthetic-OR-tags matcher (hand edit; site uses hardcoded RAIL_ORDER scaffold)
---
server.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 47 insertions(+), 7 deletions(-)
diff --git a/server.js b/server.js
index 6c58a64..7d83f6b 100644
--- a/server.js
+++ b/server.js
@@ -57,6 +57,48 @@ 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). Naive
+// `p.aesthetic === key` matching collapses rails when the aesthetic field is
+// sparse — the richer signal lives in `tags`. Prefer the shared matcher on dev;
+// fall back to a self-contained copy on prod where _shared/ 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;
+let RAIL_SYN = siteCfg.railSynonyms || {};
+if (!siteCfg.railSynonyms) { try { RAIL_SYN = require('../_shared/rail-synonyms.json'); } catch (e) {} }
+
// The PG read-path returns the canonical microsite_products columns. The Carmel
// templates also expect `sample_url` + `images` (legacy products.json fields),
// so derive them: sample = product page anchored to #sample; images = [image_url].
@@ -384,7 +426,7 @@ app.get('/api/products', (req, res) => {
});
}
if (type && type !== 'all') {
- list = list.filter(p => p.aesthetic === type);
+ list = list.filter(p => productInRail(p, type, RAIL_SYN));
}
list = sortProducts(list, sort);
const total = list.length;
@@ -398,12 +440,10 @@ app.get('/api/products', (req, res) => {
// ── API: sliders ─────────────────────────────────────────────────────────────
app.get('/api/sliders', (req, res) => {
const RAIL_ORDER = ['grasscloth','linen','botanical','coastal','raffia','natural'];
- const out = [];
- for (const a of RAIL_ORDER) {
- const items = PRODUCTS.filter(p => p.aesthetic === a).slice(0, 12);
- if (items.length >= 4) out.push({ aesthetic: a, items: items.map(IMGP.scrubProduct) });
- }
- res.json({ rails: out });
+ // Multi-membership rails via aesthetic-OR-tags + hybrid share gate (was naive
+ // p.aesthetic === a, which collapsed to empty on a sparse aesthetic field).
+ const rails = buildRails(PRODUCTS, RAIL_ORDER, { synonyms: RAIL_SYN });
+ res.json({ rails: rails.map(r => ({ aesthetic: r.aesthetic, items: r.items.map(IMGP.scrubProduct) })) });
});
// ── Health ────────────────────────────────────────────────────────────────────
← 9753035 seo: add per-page canonical + Open Graph + Twitter card (HTM
·
back to Carmelwallpapers
·
banner: wire universal promo-banner require above express.st 2be9c4b →