2929 * - `search-title` / `search-description`: a published post's search title (`seoTitle ?? title`
3030 * with the " | Sim" suffix) fits in 60 characters and its search description
3131 * (`seoDescription ?? description`) in 160, the lengths Google shows before truncating.
32+ * - `sim-count`: a library post's count of Sim's integrations, actions, or triggers is true
33+ * against the generated catalog (`INTEGRATION_TOTALS`): no higher than the total, and no
34+ * lower than 90% of it. Answer engines quote these figures, so an overclaim such as
35+ * "1,000+ integrations" or a figure left from an older catalog spreads to third-party sites.
36+ * A count belongs to Sim when the nearest "Sim" before it on the line is at most 12 words back
37+ * with no capitalized word between, which leaves competitor counts alone.
38+ * Blog and changelog posts are dated, so their counts are true as of publication.
3239 *
3340 * Run one post with `--slug <section>/<slug>` or `--slug <slug>`.
3441 */
3542import { existsSync , readdirSync , readFileSync , statSync } from 'node:fs'
3643import path from 'node:path'
3744import { compile } from '@mdx-js/mdx'
45+ import { INTEGRATION_TOTALS } from '@sim/deployment-config/integration-totals'
3846import integrationsJson from '@sim/deployment-config/integrations.json'
47+ import { formatLowerBound } from '@sim/utils/formatting'
3948import { SIM_DOCS_URL , SIM_SITE_URL } from '@sim/utils/site'
4049import matter from 'gray-matter'
4150import type { Root } from 'mdast'
@@ -65,6 +74,10 @@ export type Rule =
6574 | 'internal-link'
6675 | 'search-title'
6776 | 'search-description'
77+ | 'sim-count'
78+
79+ /** The catalog units a Sim count claim can name. */
80+ type SimCountUnit = 'integrations' | 'actions' | 'triggers'
6881
6982/** Appended to every post title by the root layout's `title.template`. */
7083const SEARCH_TITLE_SUFFIX = ' | Sim'
@@ -94,6 +107,8 @@ export interface ContentCheckConfig {
94107 customerSlugs : readonly string [ ]
95108 /** Canonical integration, model, and documentation pages served by the current source tree. */
96109 linkedPages : ReadonlySet < string >
110+ /** Sim's catalog totals that `sim-count` holds library claims to. */
111+ simCatalog : Readonly < Record < SimCountUnit , number > >
97112}
98113
99114/** Post folders per section, keyed by slug, with each post's `draft` flag. */
@@ -118,6 +133,37 @@ const MARKDOWN_LINK = /\[[^\]\n]*\]\([^)\n]*\)/
118133const FAQ_HEADING = / ^ # { 1 , 6 } \s + F A Q s ? \s * : ? \s * $ / i
119134const CODE_FENCE = / ^ \s * ( ` ` ` | ~ ~ ~ ) /
120135const ROUTE_FILES = [ 'page.tsx' , 'page.ts' , 'route.tsx' , 'route.ts' ]
136+ /** A catalog count such as "1,000+ integrations": group 1 is the number, group 2 the unit. */
137+ const COUNT_CLAIM = / \b ( \d { 1 , 3 } (?: , \d { 3 } ) + | \d + ) \+ ? \s + ( i n t e g r a t i o n s | a c t i o n s | t r i g g e r s ) \b / g
138+ const SIM_NAME = / \b S i m \b / g
139+ const SIM_CLAIM_MAX_WORDS = 12
140+ /** A Sim count below this share of the catalog total is left from an older catalog. */
141+ const SIM_COUNT_FLOOR = 0.9
142+
143+ /**
144+ * The counts on one line of text that belong to Sim, with the claim as written. A sentence or
145+ * clause that moves on to another product starts with a capitalized word, which ends Sim's claim.
146+ */
147+ function simCountClaims ( text : string ) : { claim : string ; count : number ; unit : SimCountUnit } [ ] {
148+ const claims : { claim : string ; count : number ; unit : SimCountUnit } [ ] = [ ]
149+ for ( const match of text . matchAll ( COUNT_CLAIM ) ) {
150+ const before = text . slice ( 0 , match . index )
151+ const lastSim = [ ...before . matchAll ( SIM_NAME ) ] . at ( - 1 )
152+ if ( lastSim ?. index === undefined ) continue
153+ const words = before
154+ . slice ( lastSim . index + lastSim [ 0 ] . length )
155+ . split ( / \s + / )
156+ . map ( ( word ) => word . replace ( / ^ [ ^ A - Z a - z 0 - 9 ] + / , '' ) )
157+ . filter ( Boolean )
158+ if ( words . length > SIM_CLAIM_MAX_WORDS || words . some ( ( word ) => / ^ [ A - Z ] / . test ( word ) ) ) continue
159+ claims . push ( {
160+ claim : match [ 0 ] ,
161+ count : Number . parseInt ( match [ 1 ] . replaceAll ( ',' , '' ) , 10 ) ,
162+ unit : match [ 2 ] as SimCountUnit ,
163+ } )
164+ }
165+ return claims
166+ }
121167
122168function isSection ( value : string ) : value is Section {
123169 return ( SECTIONS as readonly string [ ] ) . includes ( value )
@@ -397,6 +443,23 @@ export async function checkPost(
397443
398444 const data = parsed . data as Record < string , unknown >
399445
446+ const checkSimCounts = ( text : string , line : number ) => {
447+ if ( section !== 'library' ) return
448+ for ( const { claim, count, unit } of simCountClaims ( text ) ) {
449+ const total = config . simCatalog [ unit ]
450+ if ( count <= total && count >= total * SIM_COUNT_FLOOR ) continue
451+ report (
452+ line ,
453+ 'sim-count' ,
454+ count > total
455+ ? `"${ claim } " overstates Sim's catalog, which has ${ total } ${ unit } .`
456+ : `"${ claim } " is stale: Sim's catalog has ${ total } ${ unit } .` ,
457+ `Write ${ formatLowerBound ( total ) } ${ unit } , the catalog-derived figure (INTEGRATION_TOTALS in packages/deployment-config/src/integration-totals.ts).`
458+ )
459+ }
460+ }
461+ frontmatterLines . forEach ( ( text , index ) => checkSimCounts ( text , index + 2 ) )
462+
400463 if ( section === 'changelog' && result . success ) {
401464 const { date, updated, draft, ogAlt } = result . data
402465 if ( ! draft && ( date . getTime ( ) > Date . now ( ) || ( updated && updated . getTime ( ) > Date . now ( ) ) ) ) {
@@ -540,6 +603,7 @@ export async function checkPost(
540603 }
541604 if ( fence !== null ) return
542605 const line = bodyOffset + index + 1
606+ checkSimCounts ( text , line )
543607 if ( FAQ_HEADING . test ( text . trim ( ) ) ) {
544608 report (
545609 line ,
@@ -771,6 +835,7 @@ async function main() {
771835 movedBlogSlugs : LIBRARY_MOVED_BLOG_SLUGS ,
772836 customerSlugs : CUSTOMER_STORIES . map ( ( story ) => story . slug ) ,
773837 linkedPages : readLinkedPages ( path . join ( root , 'apps/docs' ) ) ,
838+ simCatalog : INTEGRATION_TOTALS ,
774839 }
775840
776841 const args = process . argv . slice ( 2 )
0 commit comments