Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(content): start the agent's headings and title with a capital, in the page's language (#1626)

Cihanbbf13baf7a7e
diff --git a/server/src/lib/content-writer.js b/server/src/lib/content-writer.js
index 832fbcdaa..256dc847d 100644
--- a/server/src/lib/content-writer.js
+++ b/server/src/lib/content-writer.js
@@ -222,17 +222,39 @@ const ENTITIES = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '
const escapeText = (value) => String(value).replace(/[&<>"']/g, (c) => ENTITIES[c]);
const clean = (value) => String(value ?? '').trim();
+/**
+ * A heading as a reader sees one: its first letter a capital when its first
+ * word is all lowercase, as a fan-out's words come ("latest news ChatGPT"),
+ * in the page's language (Turkish "i" → "İ"). A name written lowercase on
+ * purpose ("iPhone", "eBay") stays as it is.
+ */
+export function headingCase(text, language) {
+ const value = clean(text);
+ const [first = ''] = value.split(/\s+/u);
+ if (!first || first !== first.toLowerCase() || first === first.toUpperCase()) return value;
+ const chars = Array.from(value);
+ let capital;
+ try {
+ capital = chars[0].toLocaleUpperCase(language || undefined);
+ } catch {
+ capital = chars[0].toUpperCase();
+ }
+ return capital + chars.slice(1).join('');
+}
+
/**
* The written page as the editor's HTML: an H1, the opening paragraphs, an
- * H2 per section with its paragraphs and list, and the FAQ as H3 questions.
- * Every text is escaped: the model writes text, never markup.
+ * H2 per section with its paragraphs and list, and the FAQ as H3 questions,
+ * each heading starting with a capital (headingCase). Every text is escaped:
+ * the model writes text, never markup.
*/
-export function renderPage(page) {
+export function renderPage(page, { language = null } = {}) {
const p = (text) => (clean(text) ? `<p>${escapeText(clean(text))}</p>` : '');
- const parts = [`<h1>${escapeText(clean(page.title))}</h1>`, ...page.intro.map(p)];
+ const h = (level, text) => `<h${level}>${escapeText(headingCase(text, language))}</h${level}>`;
+ const parts = [h(1, page.title), ...page.intro.map(p)];
for (const section of page.sections) {
if (!clean(section.heading)) continue;
- parts.push(`<h2>${escapeText(clean(section.heading))}</h2>`, ...section.paragraphs.map(p));
+ parts.push(h(2, section.heading), ...section.paragraphs.map(p));
const bullets = section.bullets.filter((b) => clean(b));
if (bullets.length) {
parts.push(`<ul>${bullets.map((b) => `<li>${p(b)}</li>`).join('')}</ul>`);
@@ -240,9 +262,9 @@ export function renderPage(page) {
}
const faq = page.faq.filter((item) => clean(item.question) && clean(item.answer));
if (faq.length && clean(page.faqHeading)) {
- parts.push(`<h2>${escapeText(clean(page.faqHeading))}</h2>`);
+ parts.push(h(2, page.faqHeading));
for (const item of faq) {
- parts.push(`<h3>${escapeText(clean(item.question))}</h3>`, p(item.answer));
+ parts.push(h(3, item.question), p(item.answer));
}
}
return parts.filter(Boolean).join('');
@@ -931,13 +953,10 @@ async function writeWithRun({ draft, brand, model, input, budget, rewrite, run }
);
// The sources a claim may be given to: the ones the page gives claims to,
// its Your input and authors (editor test 2026-10-25).
- const attributable = attributableSources(
- draft.body_html,
- numbered,
- authors,
- await draftLanguage(draft, brand),
- [brand.name],
- );
+ const language = await draftLanguage(draft, brand);
+ const attributable = attributableSources(draft.body_html, numbered, authors, language, [
+ brand.name,
+ ]);
if (rewrite) {
return await rewritePage({
@@ -978,7 +997,8 @@ async function writeWithRun({ draft, brand, model, input, budget, rewrite, run }
await advanceRun(run, 3);
// No number without a source: a placeholder where one had none.
const written = sourcedPage(object, knownInPage, people);
- const title = clean(written.title).slice(0, 300) || draft.title;
+ // The title column as the H1 reads it: a capital first (headingCase).
+ const title = headingCase(clean(written.title).slice(0, 300), language) || draft.title;
// Stopped meanwhile: the page stays as it was, and History with it.
await stopIfStopped(run);
// Try again over a page the person has written in: History keeps it
@@ -997,7 +1017,7 @@ async function writeWithRun({ draft, brand, model, input, budget, rewrite, run }
// The shopping path's names it wrote, linked (shopping-links.js), and
// its products as a grid where the page names them most (shopping-blocks.js).
body_html: insertProductGrid(
- linkShoppingPath(renderPage({ ...written, title }), shoppingPath).html,
+ linkShoppingPath(renderPage({ ...written, title }, { language }), shoppingPath).html,
shoppingPath && { ...shoppingPath, pageType: draft.page_type },
),
status: 'in_review',
diff --git a/server/src/lib/content-writer.test.js b/server/src/lib/content-writer.test.js
index ae5c3f17e..69edb0dcf 100644
--- a/server/src/lib/content-writer.test.js
+++ b/server/src/lib/content-writer.test.js
@@ -96,6 +96,7 @@ vi.mock('./content-agent.js', async (importOriginal) => ({
const {
WRITE_SYSTEM_PROMPT,
buildWritePrompt,
+ headingCase,
briefText,
renderPage,
rewriteSystemPrompt,
@@ -199,6 +200,34 @@ describe('renderPage', () => {
'<h2>FAQ</h2><h3>How long?</h3><p>[time] minutes.</p>',
);
});
+
+ it('starts each heading with a capital, as a fan-out’s words come lowercase', () => {
+ const html = renderPage({
+ ...page,
+ sections: [{ heading: 'latest news ChatGPT', paragraphs: ['News.'], bullets: [] }],
+ faqHeading: 'questions',
+ faq: [{ question: 'how long does it take?', answer: 'Four minutes.' }],
+ });
+ expect(html).toContain('<h2>Latest news ChatGPT</h2>');
+ expect(html).toContain('<h2>Questions</h2><h3>How long does it take?</h3>');
+ });
+});
+
+describe('headingCase', () => {
+ it('capitalizes a lowercase first word, in the page’s language', () => {
+ expect(headingCase('latest news ChatGPT', 'en')).toBe('Latest news ChatGPT');
+ expect(headingCase('istanbul’da kahve', 'tr')).toBe('İstanbul’da kahve');
+ expect(headingCase(' çay rehberi ', 'tr')).toBe('Çay rehberi');
+ });
+
+ it('keeps a name written lowercase on purpose, a number and a heading already capitalized', () => {
+ expect(headingCase('iPhone tips for writers', 'en')).toBe('iPhone tips for writers');
+ expect(headingCase('eBay sellers', 'en')).toBe('eBay sellers');
+ expect(headingCase('2026 guide', 'en')).toBe('2026 guide');
+ expect(headingCase('Best CRM tools', 'en')).toBe('Best CRM tools');
+ // A language the runtime can't read still gets a capital.
+ expect(headingCase('latest news', 'not a locale!')).toBe('Latest news');
+ });
});
describe('sourcedPage', () => {
@@ -525,6 +554,36 @@ describe('runDraftWriting on a new page', () => {
expect(written).not.toContain('3,400');
});
+ it('saves the title as its H1 reads, a capital first, in the brand’s language', async () => {
+ generateObject.mockResolvedValue({
+ object: { ...page, title: 'latest news on pour-over coffee' },
+ usage: { inputTokens: 10, outputTokens: 20 },
+ });
+ await expect(run(draftRow())).resolves.toEqual({ written: true });
+ const saved = draftUpdates().find((u) => u.body_html);
+ expect(saved.title).toBe('Latest news on pour-over coffee');
+ expect(saved.body_html).toContain('<h1>Latest news on pour-over coffee</h1>');
+
+ // Turkish: "i" is "İ", in the title column as in the H1.
+ writes = [];
+ generateObject.mockResolvedValue({
+ object: { ...page, title: 'istanbul’da filtre kahve' },
+ usage: { inputTokens: 10, outputTokens: 20 },
+ });
+ await expect(
+ runDraftWriting({
+ draft: draftRow(),
+ brand: { ...brand, language: 'tr' },
+ model: 'model:m',
+ input: input(),
+ budget,
+ }),
+ ).resolves.toEqual({ written: true });
+ const tr = draftUpdates().find((u) => u.body_html);
+ expect(tr.title).toBe('İstanbul’da filtre kahve');
+ expect(tr.body_html).toContain('<h1>İstanbul’da filtre kahve</h1>');
+ });
+
/** A draft's shopping path as content_drafts.shopping_path keeps it. */
const shoppingPath = (over = {}) => ({
version: 1,