Pages: split 'Brand | Tagline' titles from the scan (brand names the site, tagline is the headline; generic 'Home'/'Welcome' dropped) instead of printing the raw title with its separator

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-08 14:21:34 -05:00
parent d0639aea9e
commit f59b3d2771
+19 -3
View File
@@ -125,9 +125,25 @@ async function scan(url) {
return { ok: true, scan: { url: r.url, status: r.status, title: title.slice(0, 200), description: desc.slice(0, 300), h1: h1.slice(0, 200), image, color, headings: heads, bullets: lis.slice(0, 8), scannedAt: Date.now() } };
}
// -- copy: from the scan + angle, by the model when a key exists, else a plain template
// "Brand | Tagline" page titles: the brand names the site, the tagline is the headline. Separators: | — – - · : ::
function splitTitle(title, url) {
const t = String(title || '').trim(); if (!t) return { brand: '', tagline: '' };
const GENERIC = /^(home|homepage|welcome|index|official site|official website|main page|start)$/i;
const parts = t.split(/\s+[|\u2014\u2013\-\u00b7]+\s+|\s*\|\s*|:\s+/).map(x => x.trim()).filter(x => x && !GENERIC.test(x));
if (parts.length === 1) return { brand: parts[0], tagline: '' };
if (parts.length < 2) return { brand: t, tagline: '' };
let host = ''; try { host = new URL(url || '').hostname.replace(/^www\./, '').toLowerCase(); } catch (e) {}
const bare = host.replace(/\.[a-z]+$/, '');
const looksBrand = x => { const l = x.toLowerCase().replace(/\s+/g, ''); return !!host && (l === host || l === bare || l.includes(host) || (bare.length > 3 && l.includes(bare))); };
let brand = parts.find(looksBrand) || parts.slice().sort((a, b) => a.length - b.length)[0];
const rest = parts.filter(x => x !== brand);
return { brand, tagline: rest.slice().sort((a, b) => b.length - a.length)[0] || '' };
}
function templateCopy(type, scanRes, angle, cta) {
const s = Object.assign({ bullets: [], headings: [] }, scanRes || {}); const name = s.title || s.h1 || 'this page'; const a = String(angle || '').trim();
const base = { eyebrow: type === 'review' ? 'An honest look' : 'Before you click through', headline: a || (type === 'squeeze' ? 'Get the details on ' + name : name), sub: s.description || '', bullets: (s.bullets || []).slice(0, 5), cta: { text: type === 'squeeze' ? 'Send me the details' : 'Take a look', url: cta || s.url || '' }, image: s.image || '', body: '' };
const s = Object.assign({ bullets: [], headings: [] }, scanRes || {}); const a = String(angle || '').trim();
const st = splitTitle(s.title, s.url); const name = st.brand || s.h1 || 'this page';
const head = st.tagline || s.h1 || name;
const base = { eyebrow: type === 'review' ? 'An honest look' : 'Before you click through', headline: a || (type === 'squeeze' ? 'Get the details on ' + name : head), sub: s.description || '', bullets: (s.bullets || []).slice(0, 5), cta: { text: type === 'squeeze' ? 'Send me the details' : 'Take a look', url: cta || s.url || '' }, image: s.image || '', body: '' };
if (type === 'review') Object.assign(base, { rating: 4, pros: (s.bullets || []).slice(0, 3), cons: ['Results depend on the work you put in'], verdict: 'Worth a look if ' + (a || 'this fits what you are already doing') + '.' });
if (type === 'bridge') base.body = (a ? a + '\n\n' : '') + (s.description ? s.description + '\n\n' : '') + 'I am sending you to ' + name + ' because it does what it says. Take a look, then decide.';
return base;
@@ -145,7 +161,7 @@ async function write(owner, id, body) {
const s = p.scan || {}; const angle = String(body.angle != null ? body.angle : p.angle || '').slice(0, 160); const cta = cleanUrl(body.cta || (p.content.cta && p.content.cta.url) || s.url);
let content = templateCopy(p.type, s, angle, cta), by = 'template';
try {
const ask = 'Write a ' + p.type + ' page for an internet marketer. Facts about the destination: ' + JSON.stringify({ title: s.title, description: s.description, headline: s.h1, points: s.bullets, headings: s.headings }).slice(0, 2500) + '. Angle in the marketer\'s words: "' + angle + '". Rules: plain, specific, no hype, no income promises, no em dashes, US English, first person. Return ONLY JSON with keys: eyebrow (<=60 chars), headline (<=90), sub (<=200), bullets (3-5 short strings), body (2-4 short paragraphs separated by blank lines, or empty for squeeze)' + (p.type === 'review' ? ', rating (1-5), pros (3), cons (2), verdict (<=200)' : '') + (p.type === 'bridge' ? ', bonusTitle, bonus (one short paragraph or empty)' : '') + ', ctaText (<=40).';
const ask = 'Write a ' + p.type + ' page for an internet marketer. Facts about the destination: ' + JSON.stringify({ site: splitTitle(s.title, s.url).brand || s.title, tagline: splitTitle(s.title, s.url).tagline || undefined, description: s.description, headline: s.h1, points: s.bullets, headings: s.headings }).slice(0, 2500) + '. Angle in the marketer\'s words: "' + angle + '". Rules: plain, specific, no hype, no income promises, no em dashes, US English, first person. Return ONLY JSON with keys: eyebrow (<=60 chars), headline (<=90), sub (<=200), bullets (3-5 short strings), body (2-4 short paragraphs separated by blank lines, or empty for squeeze)' + (p.type === 'review' ? ', rating (1-5), pros (3), cons (2), verdict (<=200)' : '') + (p.type === 'bridge' ? ', bonusTitle, bonus (one short paragraph or empty)' : '') + ', ctaText (<=40).';
const txt = await llm([{ role: 'system', content: 'You write short, honest marketing pages. Output JSON only.' }, { role: 'user', content: ask }]);
const j = JSON.parse((txt.match(/\{[\s\S]*\}/) || ['{}'])[0]);
if (j.headline) { content = Object.assign(content, { eyebrow: j.eyebrow, headline: j.headline, sub: j.sub, bullets: strs(j.bullets, 6, 160), body: j.body || '', rating: j.rating, pros: strs(j.pros, 6, 140), cons: strs(j.cons, 6, 140), verdict: j.verdict, bonusTitle: j.bonusTitle, bonus: j.bonus, cta: { text: j.ctaText || content.cta.text, url: cta } }); by = 'model'; }