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(cms): fill a Webflow collection's date field with the day a page is first sent (#1600)
Cihan4ad32d3dba2a
diff --git a/server/src/lib/cms/webflow-delivery.js b/server/src/lib/cms/webflow-delivery.jsindex ca4c00222..d1a1faeaa 100644--- a/server/src/lib/cms/webflow-delivery.js+++ b/server/src/lib/cms/webflow-delivery.js@@ -61,7 +61,8 @@ export async function sendToWebflow({ delivery, page, html, jsonLd, connection }const { html: body, changed } = toWebflowRichText(html);// A slug in another script has nothing left: the draft's own, the same every send.const slug = webflowSlug(page.slug) ?? webflowSlug(page.title) ?? `page-${page.draftId}`;- const fieldData = fieldDataFor({ page, slug, body, jsonLd }, connection.field_map ?? {});+ const fieldMap = connection.field_map ?? {};+ const fieldData = fieldDataFor({ page, slug, body, jsonLd }, fieldMap);try {const before = await lastItem(page.draftId, collectionId, delivery.id);let itemId = null;@@ -73,7 +74,12 @@ export async function sendToWebflow({ delivery, page, html, jsonLd, connection }}}const updated = Boolean(itemId);- itemId ??= await createItem(account, collectionId, fieldData);+ // Only a new item is given the day it's sent: one sent again keeps its date.+ itemId ??= await createItem(+ account,+ collectionId,+ fieldDataFor({ page, slug, body, jsonLd, sentAt: new Date() }, fieldMap),+ );return { taken: true, externalId: itemId, collectionId, updated, changed };} catch (err) {if (err instanceof WebflowError) {diff --git a/server/src/lib/cms/webflow-delivery.test.js b/server/src/lib/cms/webflow-delivery.test.jsindex ce1352573..635e17c77 100644--- a/server/src/lib/cms/webflow-delivery.test.js+++ b/server/src/lib/cms/webflow-delivery.test.js@@ -123,6 +123,38 @@ describe('sendToWebflow', () => {expect(webflow.createItem).not.toHaveBeenCalled();});+ it('dates a new item the day it’s sent, and leaves an item sent again its own date', async () => {+ vi.useFakeTimers({ now: new Date('2026-10-27T09:30:00Z') });+ try {+ const dated = { ...connection, field_map: { ...connection.field_map, date: 'date' } };+ const sendDated = () =>+ sendToWebflow({+ delivery: { id: 'd2345678-0000-0000-0000-000000000000' },+ page: { draftId: 'dr1', title: 'Cold brew at home', slug: 'cold-brew-at-home' },+ html: '<p>Smooth.</p>',+ jsonLd: [],+ connection: dated,+ });+ await sendDated();+ expect(webflow.createItem.mock.calls[0][2]).toMatchObject({+ date: '2026-10-27T09:30:00.000Z',+ });++ previous = 'item-old';+ await sendDated();+ expect(webflow.updateItem.mock.calls[0][3]).not.toHaveProperty('date');+ // Deleted in Webflow: the new item is dated again.+ webflow.updateItem.mockRejectedValueOnce(new WebflowError('not_found', 'gone'));+ await sendDated();+ expect(webflow.createItem.mock.calls[1][2]).toHaveProperty(+ 'date',+ '2026-10-27T09:30:00.000Z',+ );+ } finally {+ vi.useRealTimers();+ }+ });+it('gives Webflow a slug it takes, from the title when the page’s has nothing left', async () => {await send({ slug: 'soğuk.demleme' });expect(webflow.createItem.mock.calls[0][2].slug).toBe('soguk-demleme');diff --git a/server/src/lib/cms/webflow-items.js b/server/src/lib/cms/webflow-items.jsindex 35ab0651e..569449877 100644--- a/server/src/lib/cms/webflow-items.js+++ b/server/src/lib/cms/webflow-items.js@@ -226,9 +226,11 @@ function openingWords(html) {* field the brand's map gives it. The meta title falls back to the title,* the meta description to the page's opening words. JSON-LD goes as its* JSON (for an embed in the collection's template), empty when the page has- * none, so an item sent again loses what the page no longer says.+ * none, so an item sent again loses what the page no longer says. The date+ * is `sentAt` as Webflow takes it (ISO 8601), only for a new item: one sent+ * again keeps its own (a blog template's publish date).*/-export function fieldDataFor({ page, slug, body, jsonLd }, fieldMap) {+export function fieldDataFor({ page, slug, body, jsonLd, sentAt }, fieldMap) {const data = { name: squash(page.title).slice(0, NAME_CHARS), slug };if (fieldMap.body) data[fieldMap.body] = body;if (fieldMap.metaTitle) {@@ -243,5 +245,6 @@ export function fieldDataFor({ page, slug, body, jsonLd }, fieldMap) {? JSON.stringify(jsonLd.length === 1 ? jsonLd[0] : jsonLd).replace(/</g, '\\u003c'): '';}+ if (fieldMap.date && sentAt) data[fieldMap.date] = sentAt.toISOString();return data;}diff --git a/server/src/lib/cms/webflow-items.test.js b/server/src/lib/cms/webflow-items.test.jsindex aa2b2b735..47759b6fb 100644--- a/server/src/lib/cms/webflow-items.test.js+++ b/server/src/lib/cms/webflow-items.test.js@@ -147,4 +147,22 @@ describe('fieldDataFor', () => {),).toHaveProperty('schema', '');});++ it('dates a new item the day it’s sent, as ISO 8601, and leaves an item sent again its own date', () => {+ const sentAt = new Date('2026-10-27T09:30:00Z');+ const item = { page, slug: 's', body: '<p>x</p>', jsonLd: [] };+ expect(fieldDataFor({ ...item, sentAt }, { body: 'b', date: 'date' })).toEqual({+ name: 'Cold brew at home',+ slug: 's',+ b: '<p>x</p>',+ date: '2026-10-27T09:30:00.000Z',+ });+ expect(fieldDataFor(item, { body: 'b', date: 'date' })).not.toHaveProperty('date');+ // No date field in the map: nothing dated.+ expect(fieldDataFor({ ...item, sentAt }, { body: 'b' })).toEqual({+ name: 'Cold brew at home',+ slug: 's',+ b: '<p>x</p>',+ });+ });});diff --git a/server/src/lib/cms/webflow.js b/server/src/lib/cms/webflow.jsindex 58a943cd9..f8280f950 100644--- a/server/src/lib/cms/webflow.js+++ b/server/src/lib/cms/webflow.js@@ -14,10 +14,15 @@ const PART_TYPES = {metaTitle: ['PlainText'],metaDescription: ['PlainText'],jsonLd: ['PlainText'],+ date: ['DateTime'],};const PAGE_PARTS = Object.keys(PART_TYPES);-/** Webflow's own fields: every item has them, and Send to CMS always fills them. */-const OWN_FIELDS = new Set(['name', 'slug']);+/**+ * Webflow's own fields: every item has them. Send to CMS always fills its+ * name and slug; Webflow keeps its dates (getCollection leaves them out, as+ * they aren't editable).+ */+const OWN_FIELDS = new Set(['name', 'slug', 'created-on', 'updated-on', 'published-on']);/** A Webflow call that didn't go, with the code the web names to the person. */export class WebflowError extends Error {@@ -234,12 +239,15 @@ const HINTS = {metaTitle: [/(meta|seo)-?title/],metaDescription: [/(meta|seo)-?desc/, /summary/, /excerpt/, /description/],jsonLd: [/json-?ld/, /schema/, /structured/],+ date: [/publish/, /\bdate\b/, /\bposted\b/],};/*** The field map a collection's fields suggest: for each part, the first* field of a type it may go to whose slug (or name) reads as that part, one* field a part; a page's body falls back to the collection's first rich text.+ * The date goes only to a date the collection requires: the one that reads+ * as a date, else its only one.*/export function suggestFieldMap(fields) {const map = {};@@ -247,7 +255,11 @@ export function suggestFieldMap(fields) {const words = (f) => `${f.slug} ${f.name.toLowerCase().replace(/\s+/g, '-')}`;for (const part of PAGE_PARTS) {const fits = fields.filter(- (f) => PART_TYPES[part].includes(f.type) && !OWN_FIELDS.has(f.slug) && !taken.has(f.slug),+ (f) =>+ PART_TYPES[part].includes(f.type) &&+ !OWN_FIELDS.has(f.slug) &&+ !taken.has(f.slug) &&+ (part !== 'date' || f.required),);let pick = null;for (const hint of HINTS[part]) {@@ -255,6 +267,7 @@ export function suggestFieldMap(fields) {if (pick) break;}if (!pick && part === 'body') pick = fits[0] ?? null;+ if (!pick && part === 'date' && fits.length === 1) pick = fits[0];if (pick) {map[part] = pick.slug;taken.add(pick.slug);@@ -265,10 +278,11 @@ export function suggestFieldMap(fields) {/*** The parts every page has: its meta title falls back to its title, its- * meta description to its opening words. A page may have no JSON-LD, so- * that field can't be one the collection requires.+ * meta description to its opening words, and its date is the day it's first+ * sent. A page may have no JSON-LD, so that field can't be one the+ * collection requires.*/-const ALWAYS_FILLED = new Set(['body', 'metaTitle', 'metaDescription']);+const ALWAYS_FILLED = new Set(['body', 'metaTitle', 'metaDescription', 'date']);/*** Whether a field map fits the collection: a page's body has a rich textdiff --git a/server/src/lib/cms/webflow.test.js b/server/src/lib/cms/webflow.test.jsindex 2fb111591..51b13a12d 100644--- a/server/src/lib/cms/webflow.test.js+++ b/server/src/lib/cms/webflow.test.js@@ -143,6 +143,30 @@ describe('suggestFieldMap', () => {).toEqual({ body: 'intro' });expect(suggestFieldMap([{ slug: 'name', name: 'Name', type: 'PlainText' }])).toEqual({});});++ it('suggests a date the collection requires: the one named as a date, else its only one', () => {+ const date = (slug, name, required = true) => ({ slug, name, type: 'DateTime', required });+ expect(suggestFieldMap([...blog, date('date', 'Date')])).toEqual({+ body: 'post-body',+ metaDescription: 'post-summary',+ date: 'date',+ });+ expect(+ suggestFieldMap([+ ...blog,+ date('event-day', 'Event day'),+ date('publish-date', 'Publish Date'),+ ]).date,+ ).toBe('publish-date');+ expect(suggestFieldMap([...blog, date('event-day', 'Event day')]).date).toBe('event-day');+ // Two it requires, neither named as a date: the person picks.+ expect(+ suggestFieldMap([...blog, date('event-day', 'Event day'), date('ends', 'Ends')]).date,+ ).toBeUndefined();+ // A date it doesn't require isn't filled unasked, nor Webflow's own.+ expect(suggestFieldMap([...blog, date('post-date', 'Post Date', false)]).date).toBeUndefined();+ expect(suggestFieldMap([...blog, date('published-on', 'Published On')]).date).toBeUndefined();+ });});describe('checkFieldMap', () => {@@ -203,6 +227,33 @@ describe('checkFieldMap', () => {'The collection requires Post Summary, which Send to CMS doesn’t fill: make it optional in Webflow, or pick another collection',]);});++ it('fills a date the collection requires with the day a page is sent, a DateTime field only', () => {+ const fields = [+ ...blog,+ { slug: 'date', name: 'Date', type: 'DateTime', required: true },+ { slug: 'category', name: 'Category', type: 'Reference', required: false },+ ];+ expect(checkFieldMap({ body: 'post-body', date: 'date' }, fields)).toEqual({+ ok: true,+ map: { body: 'post-body', date: 'date' },+ });+ // Left unmapped, the date is still a field Send to CMS doesn't fill.+ expect(checkFieldMap({ body: 'post-body' }, fields).problems).toEqual([+ 'The collection requires Date, which Send to CMS doesn’t fill: make it optional in Webflow, or pick another collection',+ ]);+ expect(checkFieldMap({ body: 'post-body', date: 'post-summary' }, fields).problems).toEqual([+ 'date: Post Summary is PlainText, not DateTime',+ 'The collection requires Date, which Send to CMS doesn’t fill: make it optional in Webflow, or pick another collection',+ ]);+ expect(checkFieldMap({ body: 'post-body', metaDescription: 'date' }, fields).problems).toEqual(+ expect.arrayContaining(['metaDescription: Date is DateTime, not PlainText']),+ );+ // Webflow keeps its own dates.+ expect(checkFieldMap({ body: 'post-body', date: 'published-on' }, blog).problems).toEqual([+ 'date: the collection has no field "published-on"',+ ]);+ });});describe('items', () => {diff --git a/web/messages/en.json b/web/messages/en.jsonindex 98e00f3b5..96783bf54 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -8000,12 +8000,14 @@"body": "Page content (rich text)","metaTitle": "Meta title","metaDescription": "Meta description",- "jsonLd": "JSON-LD (structured data)"+ "jsonLd": "JSON-LD (structured data)",+ "date": "Date (the day it's first sent)"},"notSent": "Not sent","pickField": "Pick a field","fieldRequired": "{name} (required)","jsonLdHint": "JSON-LD goes as plain JSON. In the collection template, add an Embed that puts this field inside a JSON-LD script tag.",+ "dateHint": "The date field gets the day a page first goes to Webflow. Sending the page again leaves its date as it is.","save": "Save","saved": "Saved. Pages go to {collection}.","errors": {diff --git a/web/src/components/settings/webflow-card.test.tsx b/web/src/components/settings/webflow-card.test.tsxindex b62fd5d49..982bdba48 100644--- a/web/src/components/settings/webflow-card.test.tsx+++ b/web/src/components/settings/webflow-card.test.tsx@@ -256,6 +256,32 @@ describe('WebflowCard', () => {expect(toast.success).toHaveBeenCalledWith('Saved. Pages go to Blog Posts.');});+ it('gives a Webflow date field the day a page is first sent', async () => {+ client.readWebflow.mockResolvedValue({+ ok: true,+ configured: true,+ connection: { ...CONNECTED, fieldMap: { body: 'post-body', date: 'date' } },+ });+ client.readWebflowCollection.mockResolvedValue({+ ok: true,+ id: 'c1',+ name: 'Blog Posts',+ fields: [...FIELDS, { slug: 'date', name: 'Date', type: 'DateTime', required: true }],+ suggested: { body: 'post-body', date: 'date' },+ });+ await render();+ expect(picker("Date (the day it's first sent)").textContent).toContain('Date (required)');+ expect(container.textContent).toContain(+ 'The date field gets the day a page first goes to Webflow.',+ );+ await click(button('Save'));+ expect(client.saveWebflowSettings).toHaveBeenCalledWith('b1', {+ siteId: 's1',+ collectionId: 'c1',+ fieldMap: { body: 'post-body', date: 'date' },+ });+ });+it('lists what doesn’t fit when a map is refused', async () => {client.readWebflow.mockResolvedValue({ ok: true, configured: true, connection: CONNECTED });client.saveWebflowSettings.mockResolvedValue({diff --git a/web/src/components/settings/webflow-card.tsx b/web/src/components/settings/webflow-card.tsxindex 3930c38de..238c9c822 100644--- a/web/src/components/settings/webflow-card.tsx+++ b/web/src/components/settings/webflow-card.tsx@@ -600,6 +600,7 @@ function WebflowMapping({}))}{map.jsonLd && <p className="text-xs text-muted-foreground">{t('jsonLdHint')}</p>}+ {map.date && <p className="text-xs text-muted-foreground">{t('dateHint')}</p>}{problems.length > 0 && (<ul role="alert" className="list-disc space-y-1 pl-5 text-xs text-destructive">{problems.map((p) => (diff --git a/web/src/lib/webflow-client.ts b/web/src/lib/webflow-client.tsindex 3e8368e20..af55cb28c 100644--- a/web/src/lib/webflow-client.ts+++ b/web/src/lib/webflow-client.ts@@ -10,7 +10,7 @@ import { createClient } from '@/lib/supabase/client';*//** The parts of a page a field map places. */-export const WEBFLOW_PARTS = ['body', 'metaTitle', 'metaDescription', 'jsonLd'] as const;+export const WEBFLOW_PARTS = ['body', 'metaTitle', 'metaDescription', 'jsonLd', 'date'] as const;export type WebflowPart = (typeof WEBFLOW_PARTS)[number];export type WebflowFieldMap = Partial<Record<WebflowPart, string>>;/** The Webflow field types each part may go to. */@@ -19,6 +19,7 @@ export const WEBFLOW_PART_TYPES: Record<WebflowPart, string> = {metaTitle: 'PlainText',metaDescription: 'PlainText',jsonLd: 'PlainText',+ date: 'DateTime',};export interface WebflowConnection {