53f5d51821
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
56 lines
8.6 KiB
JavaScript
56 lines
8.6 KiB
JavaScript
// LinkSpin page renderer (2026-09-29): bridge, review and squeeze pages as standalone HTML. Everything the member
|
|
// typed is escaped; the only form on a page is either our own capture form or a provider form rebuilt by
|
|
// formrestyle (parse-or-refuse). No inline script: tracking lives in /assets/pt.js so the page can carry a real CSP.
|
|
'use strict';
|
|
const formrestyle = require('./formrestyle');
|
|
const esc = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
|
const href = u => { const s = String(u || '').trim(); return /^https?:\/\/[^\s"'<>]+$/i.test(s) && s.length <= 700 ? s : ''; };
|
|
const PALETTES = {
|
|
graphite: { bg: '#0F1422', panel: '#161D31', ink: '#EEF2F8', muted: '#A7B4CB', line: '#27314A', accent: '#3B9DFF', accentInk: '#061225', font: "'Segoe UI',system-ui,-apple-system,Roboto,sans-serif", display: "Georgia,'Times New Roman',serif" },
|
|
ink: { bg: '#F6F4EE', panel: '#FFFFFF', ink: '#17191C', muted: '#5F6670', line: '#D9D4C7', accent: '#B8410E', accentInk: '#FFFFFF', font: "'Segoe UI',system-ui,-apple-system,Roboto,sans-serif", display: "Georgia,'Times New Roman',serif" },
|
|
ember: { bg: '#1A1210', panel: '#241A16', ink: '#F7EFE9', muted: '#C9B8AE', line: '#3A2B25', accent: '#FF8A3D', accentInk: '#1A0E08', font: "'Segoe UI',system-ui,-apple-system,Roboto,sans-serif", display: "Georgia,'Times New Roman',serif" },
|
|
};
|
|
const PALETTE_NAMES = Object.keys(PALETTES);
|
|
function css(P) {
|
|
return '*{box-sizing:border-box}body{margin:0;background:' + P.bg + ';color:' + P.ink + ';font-family:' + P.font + ';font-size:17px;line-height:1.55}a{color:' + P.accent + '}'
|
|
+ '.wrap{max-width:720px;margin:0 auto;padding:28px 18px 60px}.panel{background:' + P.panel + ';border:1px solid ' + P.line + ';border-radius:12px;padding:22px}'
|
|
+ 'h1{font-family:' + P.display + ';font-size:clamp(30px,5.6vw,44px);line-height:1.08;margin:0 0 12px;text-wrap:balance}h2{font-family:' + P.display + ';font-size:24px;margin:26px 0 8px}h3{font-size:18px;margin:18px 0 6px}'
|
|
+ '.sub{font-size:19px;color:' + P.muted + ';margin:0 0 18px}.eyebrow{font-size:12px;letter-spacing:.14em;text-transform:uppercase;font-weight:700;color:' + P.accent + ';margin-bottom:10px}'
|
|
+ 'ul.checks{list-style:none;padding:0;margin:14px 0;display:grid;gap:8px}ul.checks li{padding-left:28px;position:relative}ul.checks li::before{content:"";position:absolute;left:0;top:8px;width:16px;height:16px;border-radius:50%;background:' + P.accent + '}ul.checks li::after{content:"";position:absolute;left:5px;top:11px;width:6px;height:9px;border:solid ' + P.accentInk + ';border-width:0 2px 2px 0;transform:rotate(45deg)}'
|
|
+ '.cta{display:inline-block;background:' + P.accent + ';color:' + P.accentInk + ';font-weight:800;font-size:18px;text-decoration:none;padding:15px 26px;border-radius:10px;border:0;cursor:pointer;font-family:inherit}.cta:hover{filter:brightness(1.08)}.ctawrap{margin:18px 0;text-align:center}'
|
|
+ '.lsform{display:grid;gap:10px}.lsin{width:100%;padding:14px 16px;font:16px/1.4 inherit;border:1.5px solid ' + P.line + ';border-radius:10px;background:' + P.bg + ';color:' + P.ink + '}.lsin:focus{border-color:' + P.accent + ';outline:none}'
|
|
+ '.privacy{font-size:12.5px;color:' + P.muted + ';margin:10px 0 0;text-align:center}.hero img{width:100%;height:auto;border-radius:12px;margin:0 0 18px}'
|
|
+ '.pc{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px}.pc div{background:' + P.bg + ';border:1px solid ' + P.line + ';border-radius:10px;padding:14px}.pc h3{margin:0 0 8px}.pc ul{margin:0;padding-left:18px}@media(max-width:560px){.pc{grid-template-columns:1fr}}'
|
|
+ '.rating{font-size:22px;letter-spacing:2px;color:' + P.accent + '}.verdict{border-left:4px solid ' + P.accent + ';padding:10px 14px;margin:16px 0;background:' + P.bg + ';border-radius:0 10px 10px 0}'
|
|
+ '.foot{margin-top:34px;font-size:12.5px;color:' + P.muted + ';text-align:center}.foot a{color:' + P.muted + '}p{margin:0 0 14px}';
|
|
}
|
|
const paras = t => String(t || '').split(/\n\s*\n/).map(x => x.trim()).filter(Boolean).map(x => '<p>' + esc(x).replace(/\n/g, '<br>') + '</p>').join('');
|
|
const bullets = arr => (arr || []).filter(Boolean).length ? '<ul class="checks">' + arr.filter(Boolean).map(b => '<li>' + esc(b) + '</li>').join('') + '</ul>' : '';
|
|
function stars(n) { const k = Math.max(0, Math.min(5, Math.round(Number(n) || 0))); return '<div class="rating" aria-label="' + k + ' out of 5">' + '★'.repeat(k) + '☆'.repeat(5 - k) + '</div>'; }
|
|
function ctaBtn(c, cls) { const u = href(c && c.url); const t = esc(c && c.text || 'Continue'); return u ? '<div class="ctawrap"><a class="cta ' + (cls || '') + '" href="' + esc(u) + '" data-cta>' + t + '</a></div>' : ''; }
|
|
function formArea(page, opts) {
|
|
const c = page.content || {};
|
|
if (c.formEmbed) { const parsed = formrestyle.parse(c.formEmbed); if (parsed) return '<div class="formarea">' + formrestyle.html(parsed, c.cta && c.cta.text || 'Send me the details') + '</div>'; }
|
|
// our own capture: the lead lands on the member's LinkSpin list, then the visitor continues to the CTA URL
|
|
return '<div class="formarea"><form class="lsform" method="post" action="' + esc(opts.leadUrl) + '"><input class="lsin" type="text" name="name" placeholder="Your first name"><input class="lsin" type="email" name="email" placeholder="Your best email address" required><input type="text" name="website" tabindex="-1" autocomplete="off" style="position:absolute;left:-9999px" aria-hidden="true"><input type="hidden" name="lsid" value=""><button type="submit" class="cta">' + esc(c.cta && c.cta.text || 'Send me the details') + '</button></form></div>';
|
|
}
|
|
function render(page, opts) {
|
|
opts = opts || {}; const P = PALETTES[page.design && page.design.palette] || PALETTES.graphite; const c = page.content || {};
|
|
const head = '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>' + esc(c.headline || page.title || 'Page') + '</title>'
|
|
+ '<meta name="description" content="' + esc((c.sub || '').slice(0, 160)) + '">' + (page.status !== 'published' ? '<meta name="robots" content="noindex,nofollow">' : '') + (c.image ? '<meta property="og:image" content="' + esc(href(c.image)) + '">' : '') + '<meta property="og:title" content="' + esc(c.headline || '') + '"><style>' + css(P) + '</style></head><body>';
|
|
let body = '';
|
|
const hero = c.image && href(c.image) ? '<div class="hero"><img src="' + esc(href(c.image)) + '" alt="' + esc(c.imageAlt || '') + '"></div>' : '';
|
|
if (page.type === 'squeeze') {
|
|
body = '<div class="wrap"><div class="panel">' + (c.eyebrow ? '<div class="eyebrow">' + esc(c.eyebrow) + '</div>' : '') + '<h1>' + esc(c.headline || '') + '</h1>' + (c.sub ? '<p class="sub">' + esc(c.sub) + '</p>' : '') + hero + bullets(c.bullets) + formArea(page, opts) + '<p class="privacy">' + esc(c.privacy || 'No spam, ever. Unsubscribe with one click.') + '</p></div>';
|
|
} else if (page.type === 'review') {
|
|
body = '<div class="wrap">' + (c.eyebrow ? '<div class="eyebrow">' + esc(c.eyebrow) + '</div>' : '<div class="eyebrow">Review</div>') + '<h1>' + esc(c.headline || '') + '</h1>' + (c.rating ? stars(c.rating) : '') + (c.sub ? '<p class="sub">' + esc(c.sub) + '</p>' : '') + hero + paras(c.body)
|
|
+ ((c.pros && c.pros.length) || (c.cons && c.cons.length) ? '<div class="pc"><div><h3>What works</h3><ul>' + (c.pros || []).filter(Boolean).map(x => '<li>' + esc(x) + '</li>').join('') + '</ul></div><div><h3>What to know</h3><ul>' + (c.cons || []).filter(Boolean).map(x => '<li>' + esc(x) + '</li>').join('') + '</ul></div></div>' : '')
|
|
+ (c.verdict ? '<div class="verdict"><b>Verdict.</b> ' + esc(c.verdict) + '</div>' : '') + ctaBtn(c.cta) + '</div>';
|
|
} else { // bridge
|
|
body = '<div class="wrap">' + (c.eyebrow ? '<div class="eyebrow">' + esc(c.eyebrow) + '</div>' : '') + '<h1>' + esc(c.headline || '') + '</h1>' + (c.sub ? '<p class="sub">' + esc(c.sub) + '</p>' : '') + hero + paras(c.body) + bullets(c.bullets) + ctaBtn(c.cta) + (c.bonus ? '<div class="panel"><h2 style="margin-top:0">' + esc(c.bonusTitle || 'Bonus when you join through this page') + '</h2>' + paras(c.bonus) + '</div>' : '') + ctaBtn(c.cta) + '</div>';
|
|
}
|
|
const foot = '<div class="foot">' + esc(c.disclaimer || 'Results depend on effort. Nothing here is a promise of income.') + (opts.footerLink ? ' · <a href="' + esc(opts.footerLink) + '">' + esc(opts.footerText || 'Made with LinkSpin') + '</a>' : '') + '</div>';
|
|
return head + body + foot + '<script src="' + esc(opts.trackSrc || '/assets/pt.js') + '" data-page="' + esc(page.slug) + '" defer></script></body></html>';
|
|
}
|
|
module.exports = { render, PALETTE_NAMES };
|