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): give a sent page a short slug and a meta title that ends on a word that stands (#1624)
Cihan082005549cc8
diff --git a/docs/guides/send-to-cms.mdx b/docs/guides/send-to-cms.mdxindex 9e56a6ea8..f217900b8 100644--- a/docs/guides/send-to-cms.mdx+++ b/docs/guides/send-to-cms.mdx@@ -55,8 +55,8 @@ The dialog fills the fields from the page, and you can change them before sendin| Field | Filled from ||---|---|-| **Slug** | The live page's address for an optimized page, else the title. Letters, digits, dots, `-` and `_`, up to 200 characters. |-| **Meta title** | The title. |+| **Slug** | The live page's address for an optimized page, else the title: without a leading "the" or "a", cut at a word near 60 characters, never ending on a word such as "to" or "across". Letters, digits, dots, `-` and `_`, up to 200 characters. |+| **Meta title** | The title. A long one gives its first part when it has one ("AEO tools compared side by side for marketing teams: a 2026 guide to the best" gives "AEO tools compared side by side for marketing teams") and that says enough, else it's cut at a word near 60 characters, never ending on a word such as "to" or "across". || **Meta description** | The page's first paragraph. |The slug and meta you send are kept on the draft, so the next send starts from them.diff --git a/web/src/lib/content/cms-send.test.ts b/web/src/lib/content/cms-send.test.tsindex 53ee23488..7572ecc67 100644--- a/web/src/lib/content/cms-send.test.ts+++ b/web/src/lib/content/cms-send.test.ts@@ -9,6 +9,7 @@ import {bulkCmsItems,cmsSendGroups,cmsSource,+ metaTitleOf,type CmsFields,type CmsPage,type CmsSource,@@ -33,6 +34,43 @@ const fields: CmsFields = {metaDescription: 'Brew it slowly.',};+describe('metaTitleOf', () => {+ it('keeps a title that fits, takes a long one’s first part when it says enough, else cuts it', () => {+ expect(metaTitleOf('AEO: Answer Engine Optimization for AI Search Visibility')).toBe(+ 'AEO: Answer Engine Optimization for AI Search Visibility',+ );+ expect(+ metaTitleOf('AEO tools compared side by side for marketing teams: a 2026 guide to the best'),+ ).toBe('AEO tools compared side by side for marketing teams');+ // The page that went to Webflow as "…Unified Tracking Across".+ expect(+ metaTitleOf(+ 'The Ultimate Technical Guide to Unified Tracking Across ChatGPT, Gemini, and Google AIO',+ ),+ ).toBe('The Ultimate Technical Guide to Unified Tracking');+ });++ it('never ends a Turkish title cut short on "için", in lower case or capitalized', () => {+ expect(+ metaTitleOf('Yapay zekâ aramasında görünürlük isteyen yerel markalar için en iyi rehber'),+ ).toBe('Yapay zekâ aramasında görünürlük isteyen yerel markalar');+ // "İçin".toLowerCase() is "i\u0307çin", with a combining dot: read as "için".+ expect(+ metaTitleOf('Yapay Zekâ Aramasında Görünürlük İsteyen Yerel Markalar İçin En İyi Rehber'),+ ).toBe('Yapay Zekâ Aramasında Görünürlük İsteyen Yerel Markalar');+ });++ it('gives the guide’s example as the guide says', () => {+ expect(+ metaTitleOf('AEO tools compared side by side for marketing teams: a 2026 guide to the best'),+ ).toBe('AEO tools compared side by side for marketing teams');+ // A title that fits stays whole, parts and all.+ expect(metaTitleOf('AEO tools compared: a 2026 guide')).toBe(+ 'AEO tools compared: a 2026 guide',+ );+ });+});+describe('cmsFields', () => {it('cuts the page’s meta title at a word near 60 characters, not a kept one', () => {const cut = (metaTitle: string) => cmsFields({ ...page, metaTitle }, null).metaTitle;diff --git a/web/src/lib/content/cms-send.ts b/web/src/lib/content/cms-send.tsindex f6f64ba47..d75fc7ad5 100644--- a/web/src/lib/content/cms-send.ts+++ b/web/src/lib/content/cms-send.ts@@ -9,6 +9,7 @@ import {teamName,titlePlaceholders,withByline,+ withoutDangling,withoutLeadingH1,type PageFields,} from '@/lib/content/ready-to-publish';@@ -73,14 +74,33 @@ function upToWord(text: string, max: number): string {return cut.replace(/[\s,:;|–—-]+$/u, '');}+/**+ * A meta title from the page's title: whole when it fits; else its first+ * part, when the title has parts ("Pour-over at home: a guide") and that+ * one says enough; else cut at a word near 60 characters, never on a word+ * that leads into what was cut ("…Unified Tracking Across").+ */+export function metaTitleOf(title: string): string {+ if (Array.from(title).length <= META_TITLE_PREFILL) return title;+ const [first] = title.split(/\s*[:|–—]\s+|\s+-\s+/u);+ const firstLength = Array.from(first.trim()).length;+ if (firstLength >= META_TITLE_PREFILL / 2 && firstLength <= META_TITLE_PREFILL) {+ return first.trim();+ }+ const cut = upToWord(title, META_TITLE_PREFILL);+ return withoutDangling(cut.split(/\s+/u))+ .join(' ')+ .replace(/[\s,:;|–—-]+$/u, '');+}+/*** What a send starts with: what the draft keeps, else what the page gives,- * its meta title cut at a word near 60 characters.+ * its meta title cut near 60 characters (metaTitleOf).*/export function cmsFields(fields: PageFields, kept: Partial<CmsFields> | null): CmsFields {return {slug: kept?.slug || fields.slug,- metaTitle: kept?.metaTitle || upToWord(fields.metaTitle, META_TITLE_PREFILL),+ metaTitle: kept?.metaTitle || metaTitleOf(fields.metaTitle),metaDescription: kept?.metaDescription || fields.metaDescription,};}diff --git a/web/src/lib/content/ready-to-publish.test.ts b/web/src/lib/content/ready-to-publish.test.tsindex 4c511dcc5..51045e0f5 100644--- a/web/src/lib/content/ready-to-publish.test.ts+++ b/web/src/lib/content/ready-to-publish.test.ts@@ -266,17 +266,50 @@ describe('pageFields', () => {).toBe('');});- it('cuts a long title’s slug at a word, up to 80 characters', () => {+ it('cuts a long title’s slug at a word near 60 characters, without a leading "the" or a dangling word', () => {const slug = (title: string) =>pageFields({ title, html: '', sourceUrl: null, author: null, teamByline: '' }).slug;expect(slug('Defend the coffee subscription comparison with up-to-date pricing and shipping details',),- ).toBe('defend-the-coffee-subscription-comparison-with-up-to-date-pricing-and-shipping');- // A word that ends at 80 stays whole; one word longer than 80 is cut.- expect(slug(`${'a'.repeat(80)} b`)).toBe('a'.repeat(80));- expect(slug('b'.repeat(90))).toBe('b'.repeat(80));+ ).toBe('defend-the-coffee-subscription-comparison-with-up-to-date');+ // The page that went to Webflow with an 80-character address.+ expect(+ slug(+ 'The Ultimate Technical Guide to Unified Tracking Across ChatGPT, Gemini, and Google AIO',+ ),+ ).toBe('ultimate-technical-guide-to-unified-tracking-across-chatgpt');+ // Never ending on a word that leads into what was cut.+ expect(slug('Pour-over coffee guide for home baristas who brew with a kettle and a')).toBe(+ 'pour-over-coffee-guide-for-home-baristas-who-brew',+ );+ expect(slug('The Pour-over Guide')).toBe('pour-over-guide');+ expect(slug('The')).toBe('the');+ // One word longer than 60 is cut.+ expect(slug('b'.repeat(90))).toBe('b'.repeat(60));+ expect(slug(`${'a'.repeat(60)} b`)).toBe('a'.repeat(60));+ });++ it('never ends a Turkish title’s slug on a word that leads into what was cut, as the slug spells it', () => {+ const slug = (title: string) =>+ pageFields({ title, html: '', sourceUrl: null, author: null, teamByline: '' }).slug;+ // "için" is "icin" in a slug: cut there, it goes too.+ expect(slug('Yapay zekâ aramasında görünürlük isteyen yerel markalar için en iyi rehber')).toBe(+ 'yapay-zeka-aramasinda-gorunurluk-isteyen-yerel-markalar',+ );+ expect(slug('Yapay Zekâ Aramasında Görünürlük İsteyen Yerel Markalar İçin En İyi Rehber')).toBe(+ 'yapay-zeka-aramasinda-gorunurluk-isteyen-yerel-markalar',+ );+ });++ it('drops "the", "a" or "an" only when it is the title’s first word, not a word’s start', () => {+ const slug = (title: string) =>+ pageFields({ title, html: '', sourceUrl: null, author: null, teamByline: '' }).slug;+ expect(slug('A-Frame houses guide')).toBe('a-frame-houses-guide');+ expect(slug('An-Najah alumni stories')).toBe('an-najah-alumni-stories');+ expect(slug('A guide to A-Frame houses')).toBe('guide-to-a-frame-houses');+ expect(slug('the pour-over guide')).toBe('pour-over-guide');});it('cuts a first sentence too long to fit at a word', () => {diff --git a/web/src/lib/content/ready-to-publish.ts b/web/src/lib/content/ready-to-publish.tsindex 56c27ac6a..3a0a5c4fa 100644--- a/web/src/lib/content/ready-to-publish.ts+++ b/web/src/lib/content/ready-to-publish.ts@@ -387,7 +387,65 @@ function description(root: HTMLElement): string {return `${space > 0 ? short.slice(0, space) : short}…`;}-/** A live page's own address part ("/blog/pour-over"), else the title as one. */+/**+ * Words an address or a meta title cut short shouldn't end on: they lead+ * into what was cut ("…Unified Tracking Across"). English and Turkish, the+ * languages the editor writes most.+ */+const DANGLING = new Set([+ 'a',+ 'an',+ 'the',+ 'and',+ 'or',+ 'of',+ 'to',+ 'for',+ 'in',+ 'on',+ 'at',+ 'by',+ 'with',+ 'from',+ 'across',+ 'into',+ 'vs',+ 'your',+ 'our',+ 've',+ 'ile',+ 'için',+ 'bir',+]);++/** The same words as a slug reads them: "için" is "icin" there. */+const DANGLING_SLUGS = new Set([...DANGLING].map(slugify));++/**+ * Whether a word leads into what was cut: a title's word lowercased without+ * the dot a capital "İ" leaves ("İçin" → "için", where toLowerCase gives+ * "i\u0307çin"), or a slug's word ("icin").+ */+function dangles(word: string): boolean {+ const key = word.toLowerCase().replace(/\u0307/gu, '');+ return DANGLING.has(key) || DANGLING_SLUGS.has(key);+}++/** Words without the ones a cut leaves dangling at their end, keeping one at least. */+export function withoutDangling(words: string[]): string[] {+ const kept = [...words];+ while (kept.length > 1 && dangles(kept.at(-1)!)) kept.pop();+ return kept;+}++/** A slug from the title stops about here, at a word (#1331): an address, not a sentence. */+const TITLE_SLUG_MAX = 60;++/**+ * A live page's own address part ("/blog/pour-over"), else the title as one:+ * without a leading "the" or "a", cut at a word near 60 characters, never on+ * a word that leads into what was cut.+ */export function slugOf(title: string, sourceUrl: string | null): string {if (sourceUrl) {try {@@ -400,11 +458,15 @@ export function slugOf(title: string, sourceUrl: string | null): string {// Not an address, or not one to read: the title's slug.}}- const slug = slugify(title);- if (slug.length <= 80) return slug;+ const words = slugify(title).split('-').filter(Boolean);+ // The title's own first word, not the slug's: "A-Frame houses" keeps its "a".+ if (words.length > 1 && /^(the|a|an)\s/i.test(title.trim())) words.shift();+ const slug = words.join('-');+ if (slug.length <= TITLE_SLUG_MAX) return slug;// Cut at a word, not inside one: it becomes the page's address (Send to CMS).- const cut = slug.slice(0, 81).lastIndexOf('-');- return slug.slice(0, cut > 0 ? cut : 80).replace(/-+$/, '');+ const cut = slug.slice(0, TITLE_SLUG_MAX + 1).lastIndexOf('-');+ if (cut <= 0) return slug.slice(0, TITLE_SLUG_MAX);+ return withoutDangling(slug.slice(0, cut).split('-')).join('-');}/**