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.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(content): colour the editor's length counter by the Length rule's own result (#1366)
Cihanc4d56f36bf33
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsxindex a75af2081..113581436 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx@@ -59,7 +59,7 @@ import {import { PAGE_READ_DELAY_MS, draftTitleFromDoc, safeLinkHref } from '@/lib/content/editor';import { JsonLd } from '@/lib/content/json-ld-node';import { detectPageType } from '@/lib/content/page-types';-import { aiTracesFound } from '@/lib/content/rules';+import { aiTracesFound, lengthWarns } from '@/lib/content/rules';import { saveBlob } from '@/lib/download';import { cn } from '@/lib/utils';import { AgentBar } from './_agent-bar';@@ -1068,6 +1068,7 @@ export function DraftEditor({<EditorToolbareditor={editor}target={rules.length}+ lengthWarning={lengthWarns(rules.rules)}htmlView={htmlSource !== null}onToggleHtml={htmlSource === null ? openHtmlView : applyHtmlView}onAttach={attachments.open}diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsxindex 47a968215..03a83154d 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx@@ -67,12 +67,15 @@ export function onEmptyLine(editor: Editor, state: EditorState): boolean {export function EditorToolbar({editor,target,+ lengthWarning,htmlView,onToggleHtml,onAttach,}: {editor: Editor;target: number;+ /** The Length rule is on and reads short or long (lengthWarns): amber. */+ lengthWarning: boolean;htmlView: boolean;onToggleHtml: () => void;onAttach: () => void;@@ -220,7 +223,7 @@ export function EditorToolbar({<spanclassName={cn('ml-auto text-xs font-medium tabular-nums text-muted-foreground',- state.characters > target && 'text-amber-700 dark:text-amber-400',+ lengthWarning && 'text-amber-700 dark:text-amber-400',)}>{t('counter', {diff --git a/web/src/lib/content/rules.test.ts b/web/src/lib/content/rules.test.tsindex 8b88747b5..98260e07f 100644--- a/web/src/lib/content/rules.test.ts+++ b/web/src/lib/content/rules.test.ts@@ -9,6 +9,7 @@ import {draftRulesSchema,readPage,ruleLength,+ lengthWarns,ruleSet,rulesMet,type ActiveRule,@@ -473,6 +474,24 @@ describe('rulesMet', () => {});});+describe('lengthWarns', () => {+ const statuses = (html: string, characters: number, on = true, value?: string) =>+ activeRules(ruleSet('blog_post'), {+ overrides: { length: { on, ...(value ? { value } : {}) } },+ }).map((r) => ({ rule: r, status: checkRule(r, page(html, characters), ctx) }));++ it('warns exactly when the Length rule reads short or long, as the Rules tab does', () => {+ // A 3,000 target passes 2,400–3,600: a page a little over it is fine.+ expect(lengthWarns(statuses('<h1>T</h1>', 3_300, true, '3000'))).toBe(false);+ expect(lengthWarns(statuses('<h1>T</h1>', 2_000, true, '3000'))).toBe(true);+ expect(lengthWarns(statuses('<h1>T</h1>', 3_700, true, '3000'))).toBe(true);+ });++ it('stays quiet with the Length rule off, even on an empty page', () => {+ expect(lengthWarns(statuses('', 0, false))).toBe(false);+ });+});+describe('My rules and text rules', () => {const mine = {overrides: { sentence: { value: '120' } },diff --git a/web/src/lib/content/rules.ts b/web/src/lib/content/rules.tsindex a002e431d..d0eb61164 100644--- a/web/src/lib/content/rules.ts+++ b/web/src/lib/content/rules.ts@@ -788,6 +788,17 @@ function splitSections(blocks: PageBlock[]): PageBlock[][] {return sections;}+/**+ * Whether the editor's length counter warns: exactly when the Length rule is+ * on and reads short or long, so the counter and the Rules tab never+ * disagree, whatever value or default the rule has.+ */+export function lengthWarns(statuses: { rule: ActiveRule; status: RuleStatus }[]): boolean {+ return statuses.some(+ ({ rule, status }) => rule.key === 'length' && rule.on && status.state === 'bad',+ );+}+/** How many of the rules in effect are met: off rules and ones the page can't say don't count. */export function rulesMet(statuses: { rule: ActiveRule; status: RuleStatus }[]): {met: number;