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
feat(content-editor): ask for a disclosure in Before you publish, with Add line (CE-050, part c) (#1480)
Cihanc0bd01ae8073
diff --git a/web/messages/en.json b/web/messages/en.jsonindex 81e20b4e5..a4466759d 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -4437,6 +4437,7 @@"warnings": "Before you publish: {list}.","trust": "Trust {trust}, below 60","noAuthor": "no author yet",+ "noDisclosure": "no disclosure","review": "Review","reviewLabel": "Review Before you publish"},@@ -4595,6 +4596,17 @@"other": "Schema for this page type","otherDetail": "Check what your CMS adds for it (Product, ItemList…). The code Ansvisor gives here is for articles."},+ "disclosure": {+ "ok": "Disclosure",+ "okDetail": "The page says so: \"{line}\"",+ "okReading": "The page says so: it is read again with your latest changes.",+ "none": "The page recommends {brand} without a disclosure",+ "noneDetail": "Add a line under the opening paragraph: \"{line}\" Readers and AI engines trust a page that says so.",+ "noneWrite": "Add a line saying the product the page recommends is {brand}'s own: readers and AI engines trust a page that says so.",+ "add": "Add line",+ "added": "Disclosure added",+ "addedDetail": "It is under the opening paragraph now, and counts once the page is read again. Undo takes it out."+ },"linksPending": "Still reading {count, plural, one {# of the page's links} other {# of the page's links}}, so Trust may change.","claimsReading": "Still reading the claims in your own words, so Trust may change.","pageReading": "Still reading the page for claims that need your proof, so your to-dos may change.",diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsxindex c1b6dddb7..eb4018e0d 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx@@ -89,6 +89,7 @@ const writeText = vi.fn();const clean = { placeholders: 0, imagesWithoutAlt: 0, linksBroken: 0, linksUnread: 0 };const onContinue = vi.fn();const onFillNow = vi.fn();+const onAddDisclosure = vi.fn();async function render(q: QualityRead,@@ -101,6 +102,8 @@ async function render(mode = 'markReady' as 'markReady' | 'export' | 'send',contentByline = null as string | null,title = 'How small teams forecast',+ disclosureLine = null as string | null,+ disclosureAdded = false,} = {},) {await act(async () => {@@ -121,6 +124,9 @@ async function render(linksPending={linksPending}onMarkReady={onMarkReady}onFixFirst={onFixFirst}+ disclosureLine={disclosureLine}+ disclosureAdded={disclosureAdded}+ onAddDisclosure={onAddDisclosure}/></NextIntlClientProvider>,);@@ -413,4 +419,49 @@ describe('BeforePublish', () => {expect(dialog().querySelector('pre')).toBeNull();expect(button('Copy JSON-LD')).toBeUndefined();});++ it('asks a page that puts the brand forward for its disclosure, with Add line (CE-050)', async () => {+ const line = 'Disclosure: the product this page recommends is offered by Acme.';+ const pick = { found: false, show: 'Our top pick is the Acme Ridge 28' };+ onAddDisclosure.mockReset();+ await render(quality({ aiChecks: { balanced: null, disclosure: pick } }), {+ disclosureLine: line,+ });+ expect(rows()).toContainEqual(+ expect.stringContaining('The page recommends Acme without a disclosure'),+ );+ await act(async () => button('Add line')!.click());+ expect(onAddDisclosure).toHaveBeenCalledWith(line);+ expect(rows()).toContainEqual(expect.stringContaining('Disclosure added'));+ expect(button('Add line')).toBeUndefined();+ // Opened again before the page is read: the page has the line, so it's added.+ act(() => root.unmount());+ root = createRoot(container);+ await render(quality({ aiChecks: { balanced: null, disclosure: pick } }), {+ disclosureLine: line,+ disclosureAdded: true,+ });+ expect(rows()).toContainEqual(expect.stringContaining('Disclosure added'));+ expect(button('Add line')).toBeUndefined();++ // Said: its words. No line in the page's language: the person writes it.+ await render(+ quality({+ aiChecks: { balanced: null, disclosure: { found: true, show: 'Acme makes the Ridge 28' } },+ }),+ );+ expect(rows()).toContainEqual(+ expect.stringContaining('The page says so: "Acme makes the Ridge 28"'),+ );+ act(() => root.unmount());+ root = createRoot(container);+ await render(quality({ aiChecks: { balanced: null, disclosure: pick } }));+ expect(rows()).toContainEqual(+ expect.stringContaining("Add a line saying the product the page recommends is Acme's own"),+ );+ expect(button('Add line')).toBeUndefined();+ // Where it doesn't apply: no row.+ await render(quality({ aiChecks: { balanced: null, disclosure: null } }));+ expect(rows().join(' ')).not.toContain('recommends');+ });});diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsxindex 9d2db1c5d..4d84431a5 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx@@ -1,6 +1,6 @@'use client';-import { useRef } from 'react';+import { useRef, useState } from 'react';import { useTranslations } from 'next-intl';import { AlertTriangle, Check } from 'lucide-react';import { Button } from '@/components/ui/button';@@ -40,6 +40,8 @@ type Row = {detail: string;/** Ready to paste's Fill now, while a placeholder is open. */fill?: boolean;+ /** The disclosure's Add line (CE-050): the line it puts under the H1. */+ add?: string;};/** What Ready to paste reads (Quality spec §7b): placeholders, alt text, links. */@@ -84,6 +86,9 @@ export function BeforePublish({linksPending,onMarkReady,onFixFirst,+ disclosureLine = null,+ disclosureAdded = false,+ onAddDisclosure,}: {/** Opened by Mark ready, by Export, or by Send to CMS. */mode?: 'markReady' | 'export' | 'send';@@ -108,6 +113,15 @@ export function BeforePublish({onMarkReady: (anyway: ReadyAnyway | null) => void;/** Goes to what would raise Trust, the passage named first. */onFixFirst: (show: string | null) => void;+ /**+ * Phase 2 (CE-050): the disclosure line in the page's language+ * (disclosureText), or null where there's none to offer.+ */+ disclosureLine?: string | null;+ /** The page has that line already: added, and not read again yet. */+ disclosureAdded?: boolean;+ /** Puts the disclosure line under the page's opening paragraph (undoable, as any edit). */+ onAddDisclosure?: (line: string) => void;}) {const t = useTranslations('contentEditor.editor.beforePublish');const tQuality = useTranslations('contentEditor.editor.quality');@@ -149,6 +163,10 @@ export function BeforePublish({}),): null;+ // Added here: it counts once the page is read again.+ const [added, setAdded] = useState(false);+ const disclosure = quality.aiChecks?.disclosure ?? null;+ const brand = quality.brandName || tQuality('yourBrand');const rows: Row[] = [!authorsRead? { state: 'check', title: t('author.ok'), detail: t('author.unknown') }@@ -180,6 +198,33 @@ export function BeforePublish({},]: [{ state: 'check' as const, title: t('schema.other'), detail: t('schema.otherDetail') }]),+ // Phase 2 (CE-050): where the page puts the brand forward.+ ...(disclosure+ ? [+ disclosure.found && !disclosure.added+ ? {+ state: 'ok' as const,+ title: t('disclosure.ok'),+ detail: disclosure.show+ ? t('disclosure.okDetail', { line: disclosure.show })+ : t('disclosure.okReading'),+ }+ : added || disclosureAdded+ ? {+ state: 'check' as const,+ title: t('disclosure.added'),+ detail: t('disclosure.addedDetail'),+ }+ : {+ state: 'missing' as const,+ title: t('disclosure.none', { brand }),+ detail: disclosureLine+ ? t('disclosure.noneDetail', { line: disclosureLine })+ : t('disclosure.noneWrite', { brand }),+ ...(disclosureLine && onAddDisclosure ? { add: disclosureLine } : {}),+ },+ ]+ : []),{ ...readyRow(t, paste, linksPending), fill: paste.placeholders > 0 },];@@ -278,6 +323,19 @@ export function BeforePublish({{t('paste.fill')}</Button>)}+ {row.add && (+ <Button+ size="sm"+ variant="outline"+ className="shrink-0"+ onClick={() => {+ onAddDisclosure?.(row.add!);+ setAdded(true);+ }}+ >+ {t('disclosure.add')}+ </Button>+ )}</li>))}</ul>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 52df3f7b6..b46980b65 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@@ -92,6 +92,7 @@ import { PLACEHOLDER, pagePlaceholders, placeholderIn } from '@/lib/content/placimport {blankCode,bylineText,+ disclosureText,exportPlaceholders,pasteChecks,teamName,@@ -104,13 +105,14 @@ import { inputsGiven, inputsUsed } from '@/lib/content/draft-inputs';import {eeat,linksToCheck,+ squeeze,trust,trustBlocks,unplacedSites,type ClaimMark,} from '@/lib/content/quality-checks';import { proofKey, qualityTodos } from '@/lib/content/quality-todos';-import { readability, sentencesOf } from '@/lib/content/readability';+import { isByline, readability, sentencesOf } from '@/lib/content/readability';import { brandFactsPath, factMismatches } from '@/lib/content/brand-facts';import {MAX_PROOF_TODOS,@@ -708,25 +710,32 @@ export function DraftEditor({// An edit holds what was found until the page as it is is read: while it// waits for its save too, not only once the ask is out.const pageChanging = pageRead.reading || saving;- const aiChecks = useMemo(- () =>+ // The disclosure line Add line puts in (CE-050) is the disclosure while+ // the page has it: Trust, Quality and Export count it before it is read.+ const aiChecks = useMemo(() => {+ const checks =sourcesOn &&pageRead.read?.checks &&pageRead.read.checks.pageType === (pageType ?? null) &&!pageRead.paused &&!pageRead.limited? aiChecksOnPage(pageBlocks, pageRead.read.checks, pageType, pageChanging)- : null,- [- sourcesOn,- pageRead.read,- pageChanging,- pageRead.paused,- pageRead.limited,- pageBlocks,- pageType,- ],- );+ : null;+ const line = checks?.disclosure?.found === false ? disclosureText(language, brandName) : null;+ return line && squeeze(pageBlocks.map((b) => b.text).join('')).includes(squeeze(line))+ ? { ...checks!, disclosure: { found: true, show: line, added: true } }+ : checks;+ }, [+ sourcesOn,+ pageRead.read,+ pageChanging,+ pageRead.paused,+ pageRead.limited,+ pageBlocks,+ pageType,+ language,+ brandName,+ ]);const readable = useMemo(() => (qualityOn ? readability(pageHtml, language, aiChecks?.answerFirst ?? null) : null),[qualityOn, pageHtml, language, aiChecks],@@ -1541,6 +1550,47 @@ export function DraftEditor({* said to be there.*/const htmlSourceRef = useRef<HTMLTextAreaElement>(null);+ // The disclosure line Before you publish offers (CE-050), and whether the+ // page has it already (added, and not read again yet).+ const disclosureLine = aiChecks?.disclosure ? disclosureText(language, brandName) : null;+ const disclosureOnPage =+ !!disclosureLine &&+ squeeze(pageBlocks.map((b) => b.text).join('')).includes(squeeze(disclosureLine));+ // The disclosure line (CE-050) under the page's opening paragraph (the+ // answer Answer first reads, past an image, a byline or a date), else+ // under the page's H1, else at the top; never twice. One undo takes it out.+ const addDisclosure = (line: string) => {+ if (!editor || editor.isDestroyed) return;+ const { doc } = editor.state;+ if (squeeze(doc.textContent).includes(squeeze(line))) return;+ let at = 0;+ let index = -1;+ doc.forEach((node, offset, i) => {+ const h1 = node.type.name === 'heading' && node.attrs.level === 1;+ if (index === -1 && h1 && node.textContent.trim()) {+ index = i + 1;+ at = offset + node.nodeSize;+ }+ });+ if (index !== -1) {+ const para = (i: number) =>+ i < doc.childCount && doc.child(i).type.name === 'paragraph' ? doc.child(i) : null;+ // Past what has no words (a hero image, an empty paragraph), as+ // Readability and the page read do, and a byline or a date.+ const skipped = (i: number) =>+ i < doc.childCount &&+ (!doc.child(i).textContent.trim() || (!!para(i) && isByline(doc.child(i).textContent)));+ let next = index;+ while (skipped(next)) next += 1;+ if (para(next)?.textContent.trim()) {+ for (let i = index; i <= next; i++) at += doc.child(i).nodeSize;+ }+ }+ editor+ .chain()+ .insertContentAt(at, { type: 'paragraph', content: [{ type: 'text', text: line }] })+ .run();+ };const fillFirstPlaceholder = () => {if (htmlSource !== null) {const m = new RegExp(PLACEHOLDER.source, 'iu').exec(blankCode(htmlSource, { words: true }));@@ -3086,6 +3136,7 @@ export function DraftEditor({? quality.trust.score: null,noAuthor: quality.eeat !== null && !quality.author && !authorConfirmed.real,+ noDisclosure: aiChecks?.disclosure?.found === false,article: isArticlePage(pageType),onReview: () => {setExportOpen(null);@@ -3135,6 +3186,10 @@ export function DraftEditor({pageType={pageType}image={firstImage(pageHtml)}linksPending={linksPending}+ // Not while the HTML view holds the page: its source is what goes out.+ disclosureLine={htmlSource === null ? disclosureLine : null}+ disclosureAdded={disclosureOnPage}+ onAddDisclosure={addDisclosure}onMarkReady={(anyway) => {setPublishOpen(null);void markReady(anyway ?? undefined);diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.test.tsxindex 98c90517f..1e2e75669 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.test.tsx@@ -127,6 +127,12 @@ describe('ExportDialog', () => {expect(dialog().textContent).toContain('Before you publish: Trust 45, below 60 · no author yet.Review',);+ // A page that puts the brand forward without saying the brand makes it (CE-050).+ await render({+ publish: { trustBelow: null, noAuthor: false, noDisclosure: true, article: true, onReview },+ });+ expect(dialog().textContent).toContain('Before you publish: no disclosure.Review');+ await render({ publish: { trustBelow: 45, noAuthor: true, article: true, onReview } });await act(async () => button('Review')!.click());expect(onReview).toHaveBeenCalled();// Nothing to warn about: a quiet line where the author, dates and schema are.diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.tsxindex b115adb0a..892afdd2c 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.tsx@@ -202,6 +202,8 @@ export function ExportDialog({publish?: {trustBelow: number | null;noAuthor: boolean;+ /** The page puts the brand forward without saying the brand makes it (CE-050). */+ noDisclosure?: boolean;/** An article: Before you publish has its dates and JSON-LD too. */article: boolean;onReview: () => void;@@ -626,16 +628,19 @@ export function ExportDialog({/*** Before you publish, one line over Export's options: amber with what it- * warns about (Trust under 60, no author), else quiet; Review opens it.+ * warns about (Trust under 60, no author, no disclosure), else quiet;+ * Review opens it.*/function PublishLine({trustBelow,noAuthor,+ noDisclosure = false,article,onReview,}: {trustBelow: number | null;noAuthor: boolean;+ noDisclosure?: boolean;article: boolean;onReview: () => void;}) {@@ -643,6 +648,7 @@ function PublishLine({const warnings = [...(trustBelow !== null ? [t('trust', { trust: trustBelow })] : []),...(noAuthor ? [t('noAuthor')] : []),+ ...(noDisclosure ? [t('noDisclosure')] : []),];return (<divdiff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsxindex 4d3a5af38..9c3a46f05 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx@@ -3082,6 +3082,129 @@ describe('the side panel', () => {expect(done.textContent).toContain('The proof is linked');});+ it('asks a page that puts the brand forward for its disclosure, and Add line puts it under the H1 (CE-050)', async () => {+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });+ const block = `${said} It is easy to set up for any team.`;+ getContentAuthors.mockResolvedValue({+ authors: [],+ brands: [{ id: 'b1', name: 'Ledgerly' }],+ me: { id: 'u1', role: 'admin' },+ });+ readDraftPage.mockResolvedValue({+ spots: [],+ proofs: [],+ regulated: null,+ checks: {+ answerFirst: null,+ recommends: { quote: 'Ledgerly is the fastest forecasting app', block },+ disclosure: null,+ balance: null,+ how: null,+ cut: false,+ pageType: 'best_of',+ },+ pending: false,+ limited: false,+ paused: false,+ });+ getContentDraft.mockResolvedValue({+ ...claimed,+ pageType: 'best_of',+ pageTypeSource: 'user',+ });+ window.innerWidth = 1440;+ await renderPage();+ await act(async () => void (await vi.advanceTimersByTimeAsync(3_000)));+ await act(async () => button('Mark ready')!.click());+ const line = 'Disclosure: the product this page recommends is offered by Ledgerly.';+ const dialog = document.querySelector('[role="dialog"]')!;+ expect(dialog.textContent).toContain('The page recommends Ledgerly without a disclosure');+ await act(async () =>+ [...dialog.querySelectorAll('button')].find((b) => b.textContent === 'Add line')!.click(),+ );+ const { state } = (+ container.querySelector('.ProseMirror') as HTMLElement & { editor: Editor }+ ).editor;+ // Under the opening paragraph: the answer the H1 gets first stays first.+ expect(state.doc.child(0).textContent).toBe('Pipeline forecasting');+ expect(state.doc.child(1).textContent).toBe(block);+ expect(state.doc.child(2).textContent).toBe(line);+ expect(dialog.textContent).toContain('Disclosure added');+ // Opened again before the page is read (it reads the page a moment after+ // an edit): added, not offered twice.+ await act(async () => void (await vi.advanceTimersByTimeAsync(500)));+ await act(async () =>+ [...dialog.querySelectorAll('button')].find((b) => b.textContent === 'Close')?.click(),+ );+ await act(async () => button('Mark ready')!.click());+ const again = document.querySelector('[role="dialog"]')!;+ expect(again.textContent).toContain('Disclosure added');+ expect([...again.querySelectorAll('button')].some((b) => b.textContent === 'Add line')).toBe(+ false,+ );+ });++ it('puts the disclosure line under the answer past a hero image, and counts it before the next read (review, #1480)', async () => {+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });+ const block = `${said} It is easy to set up for any team.`;+ getContentAuthors.mockResolvedValue({+ authors: [],+ brands: [{ id: 'b1', name: 'Ledgerly' }],+ me: { id: 'u1', role: 'admin' },+ });+ readDraftPage.mockResolvedValue({+ spots: [],+ proofs: [],+ regulated: null,+ checks: {+ answerFirst: null,+ recommends: { quote: 'Ledgerly is the fastest forecasting app', block },+ disclosure: null,+ balance: null,+ how: null,+ cut: false,+ pageType: 'best_of',+ },+ pending: false,+ limited: false,+ paused: false,+ });+ getContentDraft.mockResolvedValue({+ ...claimed,+ pageType: 'best_of',+ pageTypeSource: 'user',+ bodyHtml: `<h1>Pipeline forecasting</h1><img src="https://cdn.ledgerly.example/hero.png" alt="A forecast"><p></p><p>${block}</p>`,+ });+ window.innerWidth = 1440;+ await renderPage();+ await act(async () => void (await vi.advanceTimersByTimeAsync(3_000)));+ await act(async () => button('Mark ready')!.click());+ const dialog = document.querySelector('[role="dialog"]')!;+ await act(async () =>+ [...dialog.querySelectorAll('button')].find((b) => b.textContent === 'Add line')!.click(),+ );+ const { state } = (+ container.querySelector('.ProseMirror') as HTMLElement & { editor: Editor }+ ).editor;+ const texts: string[] = [];+ state.doc.forEach((node) => texts.push(node.textContent));+ // Past the image and the empty paragraph: under the answer, which stays first.+ const line = 'Disclosure: the product this page recommends is offered by Ledgerly.';+ expect(texts.indexOf(line)).toBe(texts.indexOf(block) + 1);+ // Counted before the page is read again: Quality's suggestion goes.+ await act(async () => void (await vi.advanceTimersByTimeAsync(500)));+ await act(async () =>+ [...dialog.querySelectorAll('button')].find((b) => b.textContent === 'Close')?.click(),+ );+ const chip = [...container.querySelectorAll<HTMLButtonElement>('header button')].find((b) =>+ b.textContent?.startsWith('Quality'),+ )!;+ await act(async () => chip.click());+ expect(panel()!.textContent).not.toContain('without a disclosure');+ });+it('shows a visual proof spot beside its passage, and Add image puts the image after it (CE-049)', async () => {process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });diff --git a/web/src/lib/content/page-read.ts b/web/src/lib/content/page-read.tsindex ac0ce504f..08c5876c0 100644--- a/web/src/lib/content/page-read.ts+++ b/web/src/lib/content/page-read.ts@@ -96,6 +96,8 @@ export const WEIGHING_TYPES: ReadonlySet<string> = new Set([export interface AiCheck {found: boolean;show: string | null;+ /** The disclosure line Add line put in (CE-050): counted before the page is read again. */+ added?: boolean;}/**diff --git a/web/src/lib/content/ready-to-publish.test.ts b/web/src/lib/content/ready-to-publish.test.tsindex adea26d89..4c511dcc5 100644--- a/web/src/lib/content/ready-to-publish.test.ts+++ b/web/src/lib/content/ready-to-publish.test.ts@@ -5,6 +5,7 @@ import { PLACEHOLDER } from './placeholders';import {blankCode,bylineText,+ disclosureText,exportPlaceholders,fragment,pageFields,@@ -351,6 +352,23 @@ describe('teamName', () => {});});+describe('disclosureText', () => {+ it('writes the line in the page’s language, none in another or with no brand (CE-050)', () => {+ expect(disclosureText(null, 'Acme')).toBe(+ 'Disclosure: the product this page recommends is offered by Acme.',+ );+ expect(disclosureText('tr', 'Acme')).toBe(+ 'Açıklama: Bu sayfada önerilen ürün Acme tarafından sunuluyor.',+ );+ expect(disclosureText('ja', 'Acme')).toBeNull();+ expect(disclosureText('en', ' ')).toBeNull();+ // A "$" in a name stays as it is.+ expect(disclosureText('en', 'A$1')).toBe(+ 'Disclosure: the product this page recommends is offered by A$1.',+ );+ });+});+describe('bylineText', () => {it("writes the line in the brand's language, by the author or the brand's team", () => {expect(bylineText(null, 'Ada Lovelace', 'Acme')).toBe('By Ada Lovelace');diff --git a/web/src/lib/content/ready-to-publish.ts b/web/src/lib/content/ready-to-publish.tsindex cd2af7d16..c0ee96a68 100644--- a/web/src/lib/content/ready-to-publish.ts+++ b/web/src/lib/content/ready-to-publish.ts@@ -480,6 +480,32 @@ export function teamName(language: string | null | undefined, brand: string): streturn forms ? forms.teamName.replace('{brand}', () => brand) : brand;}+/**+ * The disclosure line (CE-050) in the page's language, for a page that puts+ * the brand forward among options: what it recommends is the brand's own+ * (offered by it, which fits a product, a service or software alike). It+ * goes out with the page, so in the page's language; a language not here+ * gets none (the person writes it).+ */+const DISCLOSURES: Record<string, string> = {+ en: 'Disclosure: the product this page recommends is offered by {brand}.',+ tr: 'Açıklama: Bu sayfada önerilen ürün {brand} tarafından sunuluyor.',+ de: 'Hinweis: Das auf dieser Seite empfohlene Produkt wird von {brand} angeboten.',+ fr: 'Transparence : le produit recommandé sur cette page est proposé par {brand}.',+ es: 'Aviso: el producto que recomienda esta página lo ofrece {brand}.',+ pt: 'Aviso: o produto recomendado nesta página é oferecido por {brand}.',+ it: 'Trasparenza: il prodotto consigliato in questa pagina è offerto da {brand}.',+ nl: 'Transparantie: het product dat deze pagina aanbeveelt, wordt aangeboden door {brand}.',+ sv: 'Upplysning: produkten som den här sidan rekommenderar erbjuds av {brand}.',+};++/** The disclosure line for a page in `language`, or null (no brand read, or a language not here). */+export function disclosureText(language: string | null | undefined, brand: string): string | null {+ const line = DISCLOSURES[languageCode(language) ?? ''];+ // A function, so a "$" in a name is written as it is.+ return line && brand.trim() ? line.replace('{brand}', () => brand.trim()) : null;+}+/*** Where the end tag of the HTML's k-th H1 ends, counted from 0, or null.* Comments and code are blanked first (blankCode): an H1 there is no element.