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): align page types with the formats www.ansvisor.com offers (#1310)
Cihan7b66556449b2
diff --git a/web/messages/en.json b/web/messages/en.jsonindex 72383104c..0a256e0ea 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -3855,7 +3855,12 @@"introText": "Intro text above products","buyingFaq": "Buying tips + FAQ","currentPrices": "Prices and dates are current",- "bestTime": "Best time to visit in the summary"+ "bestTime": "Best time to visit in the summary",+ "howToSteps": "Steps as a numbered list",+ "definitionFirst": "Definition in the first sentence",+ "examplesSection": "An examples section",+ "sizeChart": "Size chart table",+ "measureSteps": "How to measure, as numbered steps"},"hints": {"summary": "A short summary under the H1 that answer engines can quote.",@@ -3865,7 +3870,9 @@"aiTraces": "Finds phrases that read as machine-written (delve, in today's fast-paced world, not only… but also). Fixing them comes with the Content Agent.","whoFor": "Who the page is for, in one sentence, e.g. \"Sales leaders at 20–200 person B2B teams\".","first40Words": "ChatGPT reads about the first 50 tokens (~40 words) of a product description. The rest is ignored.",- "feedMatch": "Checked against the product feed once it's connected."+ "feedMatch": "Checked against the product feed once it's connected.",+ "definitionFirst": "The paragraph under the H1 says what the term is (\"X is …\") in a few words: what answer engines quote for \"what is\" prompts.",+ "measureSteps": "The longest numbered list on the page counts as the steps."},"units": {"characters": "characters",@@ -3948,11 +3955,11 @@},"pageTypes": {"feature_page": "Feature page",- "solution_page": "Solution page",+ "solution_page": "Use case page","comparison": "Comparison","integration": "Integration","pricing": "Pricing",- "guide": "Guide",+ "guide": "How-to guide","blog_post": "Blog post","docs_faq": "Docs / FAQ","product_page": "Product page",@@ -3962,7 +3969,11 @@"policy": "Policy","destination_page": "Destination page","itinerary": "Itinerary",- "help_faq": "Help & FAQ"+ "help_faq": "Help & FAQ",+ "definition": "Definition page",+ "alternatives": "Alternatives page",+ "collection_page": "Collection page",+ "sizing_guide": "Sizing guide"}},"content": {diff --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 5694e3fbb..da871bae5 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@@ -295,18 +295,21 @@ describe('the content editor', () => {await rewrite('<h1>How to clean CRM data</h1>');// It reads the page once typing pauses.await act(() => new Promise((resolve) => setTimeout(resolve, 450)));- expect(typeMenu().textContent).toBe('Guide');+ expect(typeMenu().textContent).toBe('How-to guide');const types = await openTypes();expect(types.map((item) => item.textContent)).toEqual(['Feature page',- 'Solution page',+ 'Use case page','Comparison',+ 'Alternatives page',+ 'Best-of list',+ 'How-to guide',+ 'Definition page','Integration','Pricing',- 'Guide',- 'Blog post','Docs / FAQ',+ 'Blog post',]);expect(document.body.textContent).toContain('B2B SaaS page types');await act(async () => types.find((item) => item.textContent === 'Pricing')!.click());@@ -330,8 +333,15 @@ describe('the content editor', () => {expect(types.map((item) => item.textContent)).toEqual(['Product page','Category page',+ 'Collection page','Buying guide','Best-of list',+ 'Comparison',+ 'Alternatives page',+ 'How-to guide',+ 'Definition page',+ 'Sizing guide',+ 'Help & FAQ','Policy','Blog post','Feature page',diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsxindex 92e549c16..d63a0be29 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx@@ -160,12 +160,12 @@ describe('the Content plan', () => {'Daily Grind Co. and Origin Box cited · you 6%Opportunity',],[- 'Coffee subscriptionsGuide/guides/coffee-subscriptions',+ 'Coffee subscriptionsHow-to guide/guides/coffee-subscriptions','Optimize','Citations −70% on ChatGPT and PerplexityCitations',],[- 'Espresso guideGuide/guides/espresso⚠ Overlap',+ 'Espresso guideHow-to guide/guides/espresso⚠ Overlap','Protect','Top page · 12 citations · 42 AI visitsProtect',],@@ -270,7 +270,7 @@ describe('the Content plan', () => {// AI's mix (guides 40 of 60 typed) against the brand's own pages' (guides 10 of 30).// The gap shows twice: under the shares on a phone, in its column on wider screens.expect([...mix.querySelectorAll('li')].map((li) => li.textContent)).toEqual([- 'Guide67% · 33%Gap · 1 pageGap · 1 page',+ 'How-to guide67% · 33%Gap · 1 pageGap · 1 page','Blog post33% · 67%1 page',]);expect(mix.querySelector('p')!.textContent).toBe(@@ -287,8 +287,8 @@ describe('the Content plan', () => {await act(async () => guide().click());expect(guide().getAttribute('aria-pressed')).toBe('true');expect(rowTexts().map((r) => r[0])).toEqual([- 'Coffee subscriptionsGuide/guides/coffee-subscriptions',- 'Espresso guideGuide/guides/espresso⚠ Overlap',+ 'Coffee subscriptionsHow-to guide/guides/coffee-subscriptions',+ 'Espresso guideHow-to guide/guides/espresso⚠ Overlap',]);await act(async () => guide().click());expect(rowTexts()).toHaveLength(3);diff --git a/web/src/components/content/new-content-dialog.test.tsx b/web/src/components/content/new-content-dialog.test.tsxindex 3aeeeed27..c0de2d074 100644--- a/web/src/components/content/new-content-dialog.test.tsx+++ b/web/src/components/content/new-content-dialog.test.tsx@@ -149,8 +149,8 @@ describe('New content', () => {expect(checkedType()).toBe('Comparison');expect(document.body.textContent).toContain('Picked from the title.');- await click(radio('Guide'));- expect(checkedType()).toBe('Guide');+ await click(radio('How-to guide'));+ expect(checkedType()).toBe('How-to guide');await click(button('Open editor'));expect(createContentDraft).toHaveBeenCalledWith('b1', {method: 'create',@@ -173,7 +173,7 @@ describe('New content', () => {await click(option);await click(button('Continue'));expect(document.body.textContent).toContain('Create: CRM for real estate teams');- expect(checkedType()).toBe('Solution page');+ expect(checkedType()).toBe('Use case page');});it('optimizes pasted content, cleaned, and reads its page type from it', async () => {@@ -423,7 +423,7 @@ describe('New content', () => {);// The draft becomes that page's: its title, and the type its address shows.expect(document.body.textContent).toContain('Optimize: Espresso machines for beginners');- expect(checkedType()).toBe('Guide');+ expect(checkedType()).toBe('How-to guide');expect(document.body.textContent).toContain('Picked from the page.');importContentPage.mockResolvedValue({diff --git a/web/src/lib/content/drafts.ts b/web/src/lib/content/drafts.tsindex 006f51de7..82dfe78bd 100644--- a/web/src/lib/content/drafts.ts+++ b/web/src/lib/content/drafts.ts@@ -59,6 +59,11 @@ export const PAGE_TYPES = ['destination_page','itinerary','help_faq',+ // The formats www.ansvisor.com offers (content intelligence page).+ 'definition',+ 'alternatives',+ 'collection_page',+ 'sizing_guide',] as const;export type PageType = (typeof PAGE_TYPES)[number];diff --git a/web/src/lib/content/editor.ts b/web/src/lib/content/editor.tsindex fe21a9581..32ffdc405 100644--- a/web/src/lib/content/editor.ts+++ b/web/src/lib/content/editor.ts@@ -52,12 +52,15 @@ export async function bodyHash(html: string): Promise<string> {/*** The counter's target until the Rules tab (CE-009) lets it be changed: the- * spec's default Length rule, 3,000 characters, 1,200 for a product page and- * 800 for a category page.+ * spec's default Length rule, 3,000 characters; 1,200 for a product page,+ * 800 for a category or collection page, 1,000 for a sizing guide and 1,500+ * for a definition page.*/export function lengthTarget(pageType: string | null): number {if (pageType === 'product_page') return 1200;- if (pageType === 'category_page') return 800;+ if (pageType === 'category_page' || pageType === 'collection_page') return 800;+ if (pageType === 'sizing_guide') return 1000;+ if (pageType === 'definition') return 1500;return 3000;}diff --git a/web/src/lib/content/page-types.test.ts b/web/src/lib/content/page-types.test.tsindex 56f491151..c1024e02b 100644--- a/web/src/lib/content/page-types.test.ts+++ b/web/src/lib/content/page-types.test.ts@@ -43,7 +43,10 @@ describe('detectPageType from the URL', () => {['/solutions/real-estate', 'solution_page'],['/for-agencies', 'solution_page'],['/blog/northwind-vs-hubspot', 'comparison'],- ['/hubspot-alternatives/', 'comparison'],+ ['/hubspot-alternatives/', 'alternatives'],+ ['/best-crm-for-startups', 'best_of'],+ ['/glossary/lead-scoring', 'definition'],+ ['/blog/what-is-pipeline-coverage', 'definition'],['/integrations/slack', 'integration'],['/en/pricing', 'pricing'],['/guides/clean-crm-data', 'guide'],@@ -60,6 +63,12 @@ describe('detectPageType from the URL', () => {['https://shop.example/products/trail-runner-x?variant=2', 'product_page'],['/p/daypack-22l.html', 'product_page'],['/collections/ultralight-tents', 'category_page'],+ ['/collections/gifts-for-hikers', 'collection_page'],+ ['/pages/size-guide', 'sizing_guide'],+ ['/nespresso-alternatives', 'alternatives'],+ ['/compare/tent-a-vs-tent-b', 'comparison'],+ ['/faq', 'help_faq'],+ ['/guides/how-to-pitch-a-tent', 'guide'],['/buying-guides/tents', 'buying_guide'],['/best-hiking-boots', 'best_of'],['/pages/returns-policy', 'policy'],@@ -76,6 +85,8 @@ describe('detectPageType from the URL', () => {['/best-hotels-in-porto', 'best_of'],['/help/cancellation', 'help_faq'],['/guides/azores-in-winter', 'guide'],+ ['/porto-vs-lisbon', 'comparison'],+ ['/airbnb-alternatives', 'comparison'],['/blog/best-time-to-visit-madeira', 'blog_post'],])('B2C: %s → %s', (url, type) => {expect(detectPageType({ url }, 'b2c')).toBe(type);@@ -83,7 +94,9 @@ describe('detectPageType from the URL', () => {it('gives a sign the site’s own type, or skips it when the site writes no such page', () => {expect(detectPageType({ url: '/vs/hubspot' }, 'b2b')).toBe('comparison');- expect(detectPageType({ url: '/vs/hubspot' }, 'ecommerce')).toBe('best_of');+ expect(detectPageType({ url: '/vs/hubspot' }, 'ecommerce')).toBe('comparison');+ // Only a shop writes sizing guides.+ expect(detectPageType({ url: '/size-guide' }, 'b2b')).toBeNull();// A shop has no pricing page type: the URL tells nothing, the title does.expect(detectPageType({ url: '/pricing', title: 'Daypack 22L buying guide' }, 'ecommerce'),@@ -134,7 +147,13 @@ describe('detectPageType from the page', () => {it.each([['Northwind vs HubSpot', 'b2b', 'comparison'],- ['Best HubSpot alternatives', 'b2b', 'comparison'],+ ['Best HubSpot alternatives', 'b2b', 'alternatives'],+ ['HubSpot vs Salesforce', 'b2b', 'comparison'],+ ['The 10 best CRMs for startups', 'b2b', 'best_of'],+ ['What is single-origin coffee?', 'ecommerce', 'definition'],+ ['Shoe size chart', 'ecommerce', 'sizing_guide'],+ ['Gifts for coffee lovers', 'ecommerce', 'collection_page'],+ ['Shipping FAQ', 'ecommerce', 'help_faq'],['CRM for real estate teams', 'b2b', 'solution_page'],['Slack integration', 'b2b', 'integration'],['How to clean CRM data', 'b2b', 'guide'],@@ -148,6 +167,10 @@ describe('detectPageType from the page', () => {expect(detectPageType({ title }, site)).toBe(type);});+ it('doesn’t read “What is the best …” as a definition', () => {+ expect(detectPageType({ title: 'What is the best espresso machine?' }, 'ecommerce')).toBeNull();+ });+it('finds nothing when no sign tells', () => {expect(detectPageType({ title: 'Pipeline forecasting' }, 'b2b')).toBeNull();expect(detectPageType({ title: 'Best time to visit Lisbon' }, 'b2c')).toBeNull();diff --git a/web/src/lib/content/page-types.ts b/web/src/lib/content/page-types.tsindex 9162011f6..546d58b9f 100644--- a/web/src/lib/content/page-types.ts+++ b/web/src/lib/content/page-types.ts@@ -6,8 +6,11 @@ import { jsonLdScripts } from './html-allowlist';* Page types by kind of site, and a page's type found from the page itself* (Content Editor CE-023, spec §4). A B2B SaaS site writes feature,* comparison and pricing pages; a shop, product and category pages; a B2C- * site, destination and help pages. The brand's site type is set in its- * settings (brands.site_type, 00205), guessed until someone does.+ * site, destination and help pages. Every kind also writes the formats+ * www.ansvisor.com offers that fit it: how-to guides, comparisons,+ * definitions, best-of lists and FAQs; alternatives, collections and sizing+ * guides where they apply. The brand's site type is set in its settings+ * (brands.site_type, 00205), guessed until someone does.*/export const SITE_TYPES = ['b2b', 'ecommerce', 'b2c'] as const;@@ -23,14 +26,40 @@ export const SITE_PAGE_TYPES: Record<SiteType, readonly PageType[]> = {'feature_page','solution_page','comparison',+ 'alternatives',+ 'best_of',+ 'guide',+ 'definition','integration','pricing',+ 'docs_faq',+ 'blog_post',+ ],+ ecommerce: [+ 'product_page',+ 'category_page',+ 'collection_page',+ 'buying_guide',+ 'best_of',+ 'comparison',+ 'alternatives','guide',+ 'definition',+ 'sizing_guide',+ 'help_faq',+ 'policy',+ 'blog_post',+ ],+ b2c: [+ 'destination_page',+ 'itinerary',+ 'guide',+ 'best_of',+ 'comparison',+ 'definition',+ 'help_faq','blog_post',- 'docs_faq',],- ecommerce: ['product_page', 'category_page', 'buying_guide', 'best_of', 'policy', 'blog_post'],- b2c: ['destination_page', 'itinerary', 'guide', 'best_of', 'help_faq', 'blog_post'],};/**@@ -72,9 +101,18 @@ export function siteTypeOf(brand: BrandSite): SiteType {type BySite = Partial<Record<SiteType, PageType>>;const ANY_SITE = (type: PageType): BySite => ({ b2b: type, ecommerce: type, b2c: type });-const COMPARISON: BySite = { b2b: 'comparison', ecommerce: 'best_of', b2c: 'best_of' };-const HELP: BySite = { b2b: 'docs_faq', ecommerce: 'policy', b2c: 'help_faq' };-const GUIDE: BySite = { b2b: 'guide', ecommerce: 'buying_guide', b2c: 'guide' };+const COMPARISON = ANY_SITE('comparison');+const BEST_OF = ANY_SITE('best_of');+const DEFINITION = ANY_SITE('definition');+/** A B2C site has no alternatives page: an "X alternatives" page compares. */+const ALTERNATIVES: BySite = { b2b: 'alternatives', ecommerce: 'alternatives', b2c: 'comparison' };+const FAQ: BySite = { b2b: 'docs_faq', ecommerce: 'help_faq', b2c: 'help_faq' };+const POLICY: BySite = { b2b: 'docs_faq', ecommerce: 'policy', b2c: 'help_faq' };+const GUIDE = ANY_SITE('guide');+/** How to choose: a shop's buying guide, elsewhere a how-to guide. */+const BUYING_GUIDE: BySite = { b2b: 'guide', ecommerce: 'buying_guide', b2c: 'guide' };+const SIZING: BySite = { ecommerce: 'sizing_guide' };+const COLLECTION: BySite = { ecommerce: 'collection_page' };/*** URL paths, the most specific first: /blog/hubspot-vs-salesforce is a@@ -83,24 +121,29 @@ const GUIDE: BySite = { b2b: 'guide', ecommerce: 'buying_guide', b2c: 'guide' };*/const PATH_SIGNS: [RegExp, BySite][] = [[/\/(pricing|plans|plans-and-pricing)(\/|$)/, { b2b: 'pricing' }],- [- /(^|[/-])(vs|versus)([/-]|$)|\/(compare|comparisons?)(\/|$)|[/-]alternatives?([/-]|$)/,- COMPARISON,- ],+ [/\/(size-?(guides?|charts?)|sizing(-guides?)?|fit-guides?)([/-]|$)/, SIZING],+ [/(^|[/-])alternatives?([/-]|$)/, ALTERNATIVES],+ [/(^|[/-])(vs|versus)([/-]|$)|\/(compare|comparisons?)(\/|$)/, COMPARISON],+ [/\/(glossary|definitions?|dictionary|what-is|what-are)([/-]|$)/, DEFINITION],[/\/(shipping|delivery|returns?|refunds?|exchanges?|warranty|polic(y|ies)|terms|privacy|legal)([/-]|$)/,- HELP,+ POLICY,],- [/\/(docs|documentation|help|help-center|support|faqs?|knowledge-base|kb)(\/|$)/, HELP],+ [/\/(docs|documentation|help|help-center|support|faqs?|knowledge-base|kb)(\/|$)/, FAQ],[/\/(integrations?|apps|marketplace|connectors?)\//, { b2b: 'integration' }],- [/\/(buying-guides?|buyers?-guides?|how-to-choose)([/-]|$)/, GUIDE],- [/\/(the-)?(best(?!-(practices?|time|ways?)([/-]|$))|top-?\d+)([/-]|$)/, COMPARISON],+ [/\/(buying-guides?|buyers?-guides?|how-to-choose)([/-]|$)/, BUYING_GUIDE],+ [/\/(the-)?(best(?!-(practices?|time|ways?)([/-]|$))|top-?\d+)([/-]|$)/, BEST_OF],[/\/(features?|capabilities|platform)(\/|$)/, { b2b: 'feature_page' }],[/\/(solutions?|industries|industry|use-cases?|teams)(\/|$)|\/for-[a-z]/,{ b2b: 'solution_page' },],[/\/(products?|p|dp|items?)\/[^/]+/, { b2b: 'feature_page', ecommerce: 'product_page' }],+ // A themed collection (gifts, bundles, "for …") before a shop's categories.+ [+ /\/collections?\/[^/]*(gifts?|bundles?|kits?|sets?|best-?sellers?|new-arrivals?|for-[a-z]|-for-|picks|edit)/,+ COLLECTION,+ ],[/\/(collections?|categor(y|ies)|c|shop|catalog|departments?)(\/|$)/,{ ecommerce: 'category_page' },@@ -137,19 +180,26 @@ const SCHEMA_SIGNS: [readonly string[], BySite][] = [],[['Service'], { b2b: 'solution_page', b2c: 'destination_page' }],[['CollectionPage', 'OfferCatalog'], { ecommerce: 'category_page' }],+ [['DefinedTerm', 'DefinedTermSet'], DEFINITION],[['HowTo'], GUIDE],[['BlogPosting', 'Article', 'NewsArticle', 'TechArticle'], ANY_SITE('blog_post')],- [['FAQPage'], HELP],- [['ItemList'], COMPARISON],+ [['FAQPage'], FAQ],+ [['ItemList'], BEST_OF],];/** Words in the title, for a page with no telling URL or schema. */const TITLE_SIGNS: [RegExp, BySite][] = [- [/\b(vs\.?|versus)\s|\balternatives?\b/i, COMPARISON],+ [/\bsize (guide|chart)s?\b|\bsizing\b|\bfit guide\b/i, SIZING],+ [/\balternatives?\b/i, ALTERNATIVES],+ [/\b(vs\.?|versus)\s/i, COMPARISON],[/\bpricing\b/i, { b2b: 'pricing' }],- [/\bpolic(y|ies)\b|\bfaqs?\b|\bfrequently asked\b/i, HELP],- [/\bbuying guide\b|\bhow to choose\b/i, GUIDE],- [/^(the\s+)?(\d+\s+)?best\b(?!\s+(time|way|practices?)\b)|\btop\s+\d+\b/i, COMPARISON],+ [/\bpolic(y|ies)\b/i, POLICY],+ [/\bfaqs?\b|\bfrequently asked\b/i, FAQ],+ [/\bbuying guide\b|\bhow to choose\b/i, BUYING_GUIDE],+ [/^(the\s+)?(\d+\s+)?best\b(?!\s+(time|way|practices?)\b)|\btop\s+\d+\b/i, BEST_OF],+ // "What is single-origin coffee?", not "What is the best …".+ [/^what\s+(is|are)\s+(?!the\s+best\b)|\b(definition|meaning) of\b|\bglossary\b/i, DEFINITION],+ [/\bgifts? for\b|\bcollection\b/i, COLLECTION],[/\b\d+[-\s]days?\b|\bitinerar(y|ies)\b/i, { b2c: 'itinerary' }],[/\bintegrations?\b|\bintegrates? with\b/i, { b2b: 'integration' }],[diff --git a/web/src/lib/content/plan-mix.test.ts b/web/src/lib/content/plan-mix.test.tsindex 89df3947f..68235f064 100644--- a/web/src/lib/content/plan-mix.test.ts+++ b/web/src/lib/content/plan-mix.test.ts@@ -20,7 +20,7 @@ describe('pageTypeMix', () => {const { rows, covered } = pageTypeMix([cited('https://rival.example/compare/acme-vs-rival', 30),- cited('https://review.example/alternatives/crm', 10),+ cited('https://review.example/compare/crm', 10),cited('https://acme.example/vs/hubspot', 5, { own: true }),cited('https://acme.example/features/forecasting', 25, { own: true }),cited('https://acme.example/features/email-sync/', 5, { own: true }),diff --git a/web/src/lib/content/rules.test.ts b/web/src/lib/content/rules.test.tsindex 6c61f9e3e..c6f9038fd 100644--- a/web/src/lib/content/rules.test.ts+++ b/web/src/lib/content/rules.test.ts@@ -301,6 +301,64 @@ describe('page type rules', () => {});});+describe('the formats www.ansvisor.com offers', () => {+ it('gives each new page type its own rules and length', () => {+ const own = (type: Parameters<typeof ruleSet>[0]) =>+ ruleSet(type)+ .filter((r) => r.group === 'type')+ .map((r) => r.key);+ expect(own('guide')).toEqual(['howToSteps']);+ expect(own('definition')).toEqual(['definitionFirst', 'examplesSection']);+ expect(own('alternatives')).toEqual(['sideBySide', 'fairness']);+ expect(own('collection_page')).toEqual(['introText', 'buyingFaq']);+ expect(own('sizing_guide')).toEqual(['sizeChart', 'measureSteps', 'fitQuestions']);+ const length = (type: Parameters<typeof ruleSet>[0]) =>+ ruleSet(type).find((r) => r.key === 'length')?.value;+ expect([length('definition'), length('sizing_guide'), length('collection_page')]).toEqual([+ '1500',+ '1000',+ '800',+ ]);+ });++ it('checks a definition in the first sentence, short, and an examples section', () => {+ const define = (html: string) => check('definitionFirst', html, undefined, 'definition');+ expect(define('<h1>Cold brew</h1><p>Cold brew is coffee steeped in cold water.</p>')).toEqual({+ state: 'ok',+ });+ expect(define('<h1>Cold brew</h1><p>Many people love it in summer.</p>')).toEqual({+ state: 'bad',+ code: 'missing',+ });+ expect(define(`<h1>Cold brew</h1><p>Cold brew is ${'very '.repeat(60)}cold.</p>`)).toEqual({+ state: 'bad',+ code: 'words',+ count: 64,+ });+ expect(+ check('examplesSection', '<h2>Examples of cold brew</h2>', undefined, 'definition'),+ ).toEqual({ state: 'ok' });+ });++ it('checks a how-to guide’s and a sizing guide’s steps, and a size chart', () => {+ const steps = '<ol><li>a</li><li>b</li><li>c</li></ol>';+ expect(check('howToSteps', steps, undefined, 'guide')).toEqual({ state: 'ok' });+ expect(check('measureSteps', '<ol><li>a</li></ol>', undefined, 'sizing_guide')).toEqual({+ state: 'bad',+ code: 'partOf',+ count: 1,+ of: 3,+ });+ expect(+ check('sizeChart', '<table><tr><td>M</td></tr></table>', undefined, 'sizing_guide'),+ ).toEqual({ state: 'ok' });+ expect(check('sizeChart', '<p>M fits most</p>', undefined, 'sizing_guide')).toEqual({+ state: 'bad',+ code: 'missing',+ });+ });+});+describe('rulesMet', () => {it('counts the rules on that the page can say', () => {const rules = activeRules(ruleSet('blog_post'), {diff --git a/web/src/lib/content/rules.ts b/web/src/lib/content/rules.tsindex 52e97069b..5ffec0a29 100644--- a/web/src/lib/content/rules.ts+++ b/web/src/lib/content/rules.ts@@ -175,6 +175,68 @@ const TYPE_RULES: Partial<Record<PageType, RuleDef[]>> = {{ key: 'currentPrices', group: 'type', kind: 'switch', value: '', check: 'ai' },{ key: 'bestTime', group: 'type', kind: 'switch', value: '', check: 'page' },],+ guide: [+ {+ key: 'howToSteps',+ group: 'type',+ kind: 'number',+ value: '3',+ unit: 'steps',+ check: 'page',+ },+ ],+ definition: [+ {+ key: 'definitionFirst',+ group: 'type',+ kind: 'number',+ value: '60',+ unit: 'wordsMax',+ check: 'page',+ },+ { key: 'examplesSection', group: 'type', kind: 'switch', value: '', check: 'page' },+ ],+ alternatives: [+ { key: 'sideBySide', group: 'type', kind: 'switch', value: '', check: 'page' },+ { key: 'fairness', group: 'type', kind: 'switch', value: '', check: 'ai' },+ ],+ collection_page: [+ {+ key: 'introText',+ group: 'type',+ kind: 'number',+ value: '120',+ unit: 'wordsMin',+ check: 'page',+ },+ {+ key: 'buyingFaq',+ group: 'type',+ kind: 'number',+ value: '3',+ unit: 'questions',+ check: 'page',+ },+ ],+ sizing_guide: [+ { key: 'sizeChart', group: 'type', kind: 'switch', value: '', check: 'page' },+ {+ key: 'measureSteps',+ group: 'type',+ kind: 'number',+ value: '3',+ unit: 'steps',+ check: 'page',+ },+ {+ key: 'fitQuestions',+ group: 'type',+ kind: 'number',+ value: '3',+ unit: 'questions',+ check: 'page',+ },+ ],};/** The rules of a set: the type's own, then the shared groups, with the type's length. */@@ -556,6 +618,7 @@ export function checkRule(rule: ActiveRule, page: PageRead, ctx: RuleContext): Rcase 'comparisonTable':case 'sideBySide':case 'specsTable':+ case 'sizeChart':return blocks.some((b) => b.tag === 'table')? { state: 'ok' }: { state: 'bad', code: 'missing' };@@ -568,7 +631,9 @@ export function checkRule(rule: ActiveRule, page: PageRead, ctx: RuleContext): R).length;return atLeast(proven, sections.length);}- case 'useCaseSteps': {+ case 'useCaseSteps':+ case 'howToSteps':+ case 'measureSteps': {const most = Math.max(0,...blocks.filter((b) => b.tag.startsWith('ol:')).map((b) => Number(b.tag.slice(3))),@@ -588,6 +653,19 @@ export function checkRule(rule: ActiveRule, page: PageRead, ctx: RuleContext): R.reduce((sum, b) => sum + b.words, 0);return words >= n ? { state: 'ok' } : { state: 'bad', code: 'current', count: words };}+ case 'definitionFirst':+ // The term defined at once: "X is …" in a short first paragraph.+ if (!summary || !summary.words) return { state: 'bad', code: 'missing' };+ if (!/\b(is|are|refers to|means)\b/i.test(summary.text)) {+ return { state: 'bad', code: 'missing' };+ }+ return summary.words <= n+ ? { state: 'ok' }+ : { state: 'bad', code: 'words', count: summary.words };+ case 'examplesSection':+ return blocks.some((b) => isHeading(b) && /\bexamples?\b/i.test(b.text))+ ? { state: 'ok' }+ : { state: 'bad', code: 'missing' };case 'bestTime':return summary && /\bbest time\b/i.test(summary.text)? { state: 'ok' }