/** * ═══════════════════════════════════════════════════ * 小红书卡片模板 · 2026审美版 · 1080×1440 (3:4) * ═══════════════════════════════════════════════════ * * 风格:极简大标题 + 高对比度 + 大面积留白 + 渐变色块 * 支持 CSS 变量驱动配色(从 registry 预设传入) * * 布局: * - default: 标题 + 正文列表(教程/干货) * - quote: 金句居中大字 * - hero: 大标题 + 一句话副标题(封面) */ import { STYLES } from '../config.js' const W = 1080 const H = 1440 /** * 将 CSS 变量对象转换为 :root 样式 */ function cssVarBlock(vars = {}) { const lines = Object.entries(vars).map(([k, v]) => ` ${k}: ${v};`) return `:root {\n${lines.join('\n')}\n }` } /** * 生成小红书卡片 HTML */ export function xiaohongshuCard(data) { const { title = '', body = '', subtitle = '', tag = '', layout = 'default', pageNum = 1, totalPages = 1, cssVars = {}, } = data const bodyLines = body.split('\n').filter(Boolean) // 渲染正文:支持列表、小标题、加粗 const bodyHtml = bodyLines.map(line => { const trimmed = line.trimStart() if (trimmed.startsWith('- ') || trimmed.startsWith('• ')) { const text = trimmed.replace(/^[-•]\s*/, '') return `
  • ${text}
  • ` } if (trimmed.startsWith('## ')) { return `

    ${trimmed.slice(3)}

    ` } const formatted = trimmed.replace(/\*\*(.+?)\*\*/g, '$1') return `

    ${formatted}

    ` }).join('\n') const C = { bg: 'var(--bg, #faf8f5)', primary: 'var(--primary, #1a1a2e)', accent: 'var(--accent, #4f8cff)', highlight: 'var(--highlight, #00d4ff)', gold: 'var(--gold, #c9a96e)', warm: 'var(--warm, #f5e6c8)', text: 'var(--text, #1a1a2e)', textMuted: 'var(--textMuted, #6b7280)', cardBg: 'var(--cardBg, #ffffff)', border: 'var(--border, #e5e7eb)', } return `
    ${tag ? `
    ${tag}
    ` : ''} ${layout === 'quote' ? `
    "
    ${title}
    ${subtitle ? `
    —— ${subtitle}
    ` : ''}
    ` : layout === 'hero' ? `
    ${title}
    ${subtitle ? `
    ${subtitle}
    ` : ''}
    ` : `
    ${title}
    ${subtitle ? `
    ${subtitle}
    ` : ''}
    ${bodyHtml}
    `}
    ` } export function xiaohongshuCarousel(data, pages) { return pages.map((body, i) => xiaohongshuCard({ ...data, body, pageNum: i + 1, totalPages: pages.length, })) }