← back to Goldleafwallpaper

scripts/ig-poster/caption.js

74 lines

// caption.js — build the per-SKU Instagram "info" caption for @goldleafwallpaper.
// Input fields are empty of price by design (the RML line is trade/quote-only),
// so captions lead with FINISH + COLORWAY + STYLE and always carry the
// free-memo-sample CTA + link-in-bio, matching the site + IG bio voice.

// Colorway words worth surfacing (order = display priority).
const COLOR_PRIORITY = [
  'Gold', 'Brass', 'Bronze', 'Champagne', 'Silver', 'Platinum', 'Pewter',
  'Copper', 'Black', 'Charcoal', 'Chocolate', 'Cream', 'Beige',
  'Taupe', 'White', 'Gray', 'Grey', 'Yellow', 'Green', 'Blue', 'Red',
];
// Style words worth surfacing; generic/structural tags are demoted (used only
// if nothing more descriptive is present).
// NB: "Renaissance" is deliberately omitted — it's the collection name and
// already leads line 1, so line 2 surfaces the actual motif instead of repeating.
const STYLE_PRIORITY = [
  'Organic Modern', 'Art Deco', 'Botanical', 'Floral',
  'Geometric', 'Abstract', 'Damask', 'Stripe',
];
const STYLE_FALLBACK = ['Textured', 'Metallic', 'Solid', 'Pattern'];

// A rotating set of on-brand hashtag blocks so every post isn't identical
// (IG down-ranks copy-paste captions). Selected by SKU index, deterministic.
const HASHTAG_BLOCKS = [
  '#goldwallpaper #metalleaf #luxurywallcovering #interiordesign #interiordesigner #luxuryinteriors #wallcovering #metallicwallpaper #designertrade #interiorstyling',
  '#goldleaf #metallicwallpaper #wallcovering #interiordesign #luxuryhome #designerwallpaper #hospitalitydesign #walldecor #interiordesigners #trade',
  '#metalleafwallpaper #goldwallpaper #luxuryinteriors #interiordesign #wallcoverings #designtrade #accentwall #interiordecor #wallpaperlove #bespokeinteriors',
];

function pick(list, priority, fallback) {
  const set = new Set(list);
  const hit = priority.find((w) => set.has(w));
  if (hit) return hit;
  if (fallback) return fallback.find((w) => set.has(w)) || null;
  return null;
}

// Build up to two colorway words into a phrase, e.g. "gold & black".
function colorwayPhrase(tags) {
  const set = new Set(tags);
  const picks = [];
  for (const c of COLOR_PRIORITY) {
    if (set.has(c) && !picks.includes(c)) picks.push(c);
    if (picks.length === 2) break;
  }
  if (!picks.length) return 'metallic';
  return picks.map((c) => c.toLowerCase()).join(' & ');
}

function buildCaption(product, index = 0) {
  const tags = (product.tags || '').split(',').map((s) => s.trim()).filter(Boolean);
  const dwSku = product.dw_sku || '';
  const material = product.material || 'Metal Leaf';
  const colorway = colorwayPhrase(tags);
  const style = pick(tags, STYLE_PRIORITY, STYLE_FALLBACK);

  const styleClause = style ? `${style} ` : '';
  const line1 = '✦ Renaissance Metal Leaf'; // ✦
  const line2 = `${cap(styleClause)}metal-leaf wallcovering in ${colorway} — hand-applied, light-catching, made to carry the wall.`;
  const line3 = dwSku
    ? `SKU ${dwSku} · trade source · free designer memo samples.`
    : 'Trade source · free designer memo samples.';
  const line4 = '📍 goldleafwallpaper.com — link in bio'; // 📍
  const tagsBlock = HASHTAG_BLOCKS[index % HASHTAG_BLOCKS.length];

  return [line1, line2, line3, line4, '.', tagsBlock].join('\n');
}

function cap(s) {
  return s ? s.charAt(0).toUpperCase() + s.slice(1) : s;
}

module.exports = { buildCaption };