@rankcli/agent-runtime 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.md +242 -0
  2. package/dist/analyzer-2CSWIQGD.mjs +6 -0
  3. package/dist/chunk-YNZYHEYM.mjs +774 -0
  4. package/dist/index.d.mts +4012 -0
  5. package/dist/index.d.ts +4012 -0
  6. package/dist/index.js +29672 -0
  7. package/dist/index.mjs +28602 -0
  8. package/package.json +53 -0
  9. package/scripts/build-deno.ts +134 -0
  10. package/src/audit/ai/analyzer.ts +347 -0
  11. package/src/audit/ai/index.ts +29 -0
  12. package/src/audit/ai/prompts/content-analysis.ts +271 -0
  13. package/src/audit/ai/types.ts +179 -0
  14. package/src/audit/checks/additional-checks.ts +439 -0
  15. package/src/audit/checks/ai-citation-worthiness.ts +399 -0
  16. package/src/audit/checks/ai-content-structure.ts +325 -0
  17. package/src/audit/checks/ai-readiness.ts +339 -0
  18. package/src/audit/checks/anchor-text.ts +179 -0
  19. package/src/audit/checks/answer-conciseness.ts +322 -0
  20. package/src/audit/checks/asset-minification.ts +270 -0
  21. package/src/audit/checks/bing-optimization.ts +206 -0
  22. package/src/audit/checks/brand-mention-optimization.ts +349 -0
  23. package/src/audit/checks/caching-headers.ts +305 -0
  24. package/src/audit/checks/canonical-advanced.ts +150 -0
  25. package/src/audit/checks/canonical-domain.ts +196 -0
  26. package/src/audit/checks/citation-quality.ts +358 -0
  27. package/src/audit/checks/client-rendering.ts +542 -0
  28. package/src/audit/checks/color-contrast.ts +342 -0
  29. package/src/audit/checks/content-freshness.ts +170 -0
  30. package/src/audit/checks/content-science.ts +589 -0
  31. package/src/audit/checks/conversion-elements.ts +526 -0
  32. package/src/audit/checks/crawlability.ts +220 -0
  33. package/src/audit/checks/directory-listing.ts +172 -0
  34. package/src/audit/checks/dom-analysis.ts +191 -0
  35. package/src/audit/checks/dom-size.ts +246 -0
  36. package/src/audit/checks/duplicate-content.ts +194 -0
  37. package/src/audit/checks/eeat-signals.ts +990 -0
  38. package/src/audit/checks/entity-seo.ts +396 -0
  39. package/src/audit/checks/featured-snippet.ts +473 -0
  40. package/src/audit/checks/freshness-signals.ts +443 -0
  41. package/src/audit/checks/funnel-intent.ts +463 -0
  42. package/src/audit/checks/hreflang.ts +174 -0
  43. package/src/audit/checks/html-compliance.ts +302 -0
  44. package/src/audit/checks/image-dimensions.ts +167 -0
  45. package/src/audit/checks/images.ts +160 -0
  46. package/src/audit/checks/indexnow.ts +275 -0
  47. package/src/audit/checks/interactive-tools.ts +475 -0
  48. package/src/audit/checks/internal-link-graph.ts +436 -0
  49. package/src/audit/checks/keyword-analysis.ts +239 -0
  50. package/src/audit/checks/keyword-cannibalization.ts +385 -0
  51. package/src/audit/checks/keyword-placement.ts +471 -0
  52. package/src/audit/checks/links.ts +203 -0
  53. package/src/audit/checks/llms-txt.ts +224 -0
  54. package/src/audit/checks/local-seo.ts +296 -0
  55. package/src/audit/checks/mobile.ts +167 -0
  56. package/src/audit/checks/modern-images.ts +226 -0
  57. package/src/audit/checks/navboost-signals.ts +395 -0
  58. package/src/audit/checks/on-page.ts +209 -0
  59. package/src/audit/checks/page-resources.ts +285 -0
  60. package/src/audit/checks/pagination.ts +180 -0
  61. package/src/audit/checks/performance.ts +153 -0
  62. package/src/audit/checks/platform-presence.ts +580 -0
  63. package/src/audit/checks/redirect-analysis.ts +153 -0
  64. package/src/audit/checks/redirect-chain.ts +389 -0
  65. package/src/audit/checks/resource-hints.ts +420 -0
  66. package/src/audit/checks/responsive-css.ts +247 -0
  67. package/src/audit/checks/responsive-images.ts +396 -0
  68. package/src/audit/checks/review-ecosystem.ts +415 -0
  69. package/src/audit/checks/robots-validation.ts +373 -0
  70. package/src/audit/checks/security-headers.ts +172 -0
  71. package/src/audit/checks/security.ts +144 -0
  72. package/src/audit/checks/serp-preview.ts +251 -0
  73. package/src/audit/checks/site-maturity.ts +444 -0
  74. package/src/audit/checks/social-meta.test.ts +275 -0
  75. package/src/audit/checks/social-meta.ts +134 -0
  76. package/src/audit/checks/soft-404.ts +151 -0
  77. package/src/audit/checks/structured-data.ts +238 -0
  78. package/src/audit/checks/tech-detection.ts +496 -0
  79. package/src/audit/checks/topical-clusters.ts +435 -0
  80. package/src/audit/checks/tracker-bloat.ts +462 -0
  81. package/src/audit/checks/tracking-verification.test.ts +371 -0
  82. package/src/audit/checks/tracking-verification.ts +636 -0
  83. package/src/audit/checks/url-safety.ts +682 -0
  84. package/src/audit/deno-entry.ts +66 -0
  85. package/src/audit/discovery/index.ts +15 -0
  86. package/src/audit/discovery/link-crawler.ts +232 -0
  87. package/src/audit/discovery/repo-routes.ts +347 -0
  88. package/src/audit/engine.ts +620 -0
  89. package/src/audit/fixes/index.ts +209 -0
  90. package/src/audit/fixes/social-meta-fixes.test.ts +329 -0
  91. package/src/audit/fixes/social-meta-fixes.ts +463 -0
  92. package/src/audit/index.ts +74 -0
  93. package/src/audit/runner.test.ts +299 -0
  94. package/src/audit/runner.ts +130 -0
  95. package/src/audit/types.ts +1953 -0
  96. package/src/content/featured-snippet.ts +367 -0
  97. package/src/content/generator.test.ts +534 -0
  98. package/src/content/generator.ts +501 -0
  99. package/src/content/headline.ts +317 -0
  100. package/src/content/index.ts +62 -0
  101. package/src/content/intent.ts +258 -0
  102. package/src/content/keyword-density.ts +349 -0
  103. package/src/content/readability.ts +262 -0
  104. package/src/executor.ts +336 -0
  105. package/src/fixer.ts +416 -0
  106. package/src/frameworks/detector.test.ts +248 -0
  107. package/src/frameworks/detector.ts +371 -0
  108. package/src/frameworks/index.ts +68 -0
  109. package/src/frameworks/recipes/angular.yaml +171 -0
  110. package/src/frameworks/recipes/astro.yaml +206 -0
  111. package/src/frameworks/recipes/django.yaml +180 -0
  112. package/src/frameworks/recipes/laravel.yaml +137 -0
  113. package/src/frameworks/recipes/nextjs.yaml +268 -0
  114. package/src/frameworks/recipes/nuxt.yaml +175 -0
  115. package/src/frameworks/recipes/rails.yaml +188 -0
  116. package/src/frameworks/recipes/react.yaml +202 -0
  117. package/src/frameworks/recipes/sveltekit.yaml +154 -0
  118. package/src/frameworks/recipes/vue.yaml +137 -0
  119. package/src/frameworks/recipes/wordpress.yaml +209 -0
  120. package/src/frameworks/suggestion-engine.ts +320 -0
  121. package/src/geo/geo-content.test.ts +305 -0
  122. package/src/geo/geo-content.ts +266 -0
  123. package/src/geo/geo-history.test.ts +473 -0
  124. package/src/geo/geo-history.ts +433 -0
  125. package/src/geo/geo-tracker.test.ts +359 -0
  126. package/src/geo/geo-tracker.ts +411 -0
  127. package/src/geo/index.ts +10 -0
  128. package/src/git/commit-helper.test.ts +261 -0
  129. package/src/git/commit-helper.ts +329 -0
  130. package/src/git/index.ts +12 -0
  131. package/src/git/pr-helper.test.ts +284 -0
  132. package/src/git/pr-helper.ts +307 -0
  133. package/src/index.ts +66 -0
  134. package/src/keywords/ai-keyword-engine.ts +1062 -0
  135. package/src/keywords/ai-summarizer.ts +387 -0
  136. package/src/keywords/ci-mode.ts +555 -0
  137. package/src/keywords/engine.ts +359 -0
  138. package/src/keywords/index.ts +151 -0
  139. package/src/keywords/llm-judge.ts +357 -0
  140. package/src/keywords/nlp-analysis.ts +706 -0
  141. package/src/keywords/prioritizer.ts +295 -0
  142. package/src/keywords/site-crawler.ts +342 -0
  143. package/src/keywords/sources/autocomplete.ts +139 -0
  144. package/src/keywords/sources/competitive-search.ts +450 -0
  145. package/src/keywords/sources/competitor-analysis.ts +374 -0
  146. package/src/keywords/sources/dataforseo.ts +206 -0
  147. package/src/keywords/sources/free-sources.ts +294 -0
  148. package/src/keywords/sources/gsc.ts +123 -0
  149. package/src/keywords/topic-grouping.ts +327 -0
  150. package/src/keywords/types.ts +144 -0
  151. package/src/keywords/wizard.ts +457 -0
  152. package/src/loader.ts +40 -0
  153. package/src/reports/index.ts +7 -0
  154. package/src/reports/report-generator.test.ts +293 -0
  155. package/src/reports/report-generator.ts +713 -0
  156. package/src/scheduler/alerts.test.ts +458 -0
  157. package/src/scheduler/alerts.ts +328 -0
  158. package/src/scheduler/index.ts +8 -0
  159. package/src/scheduler/scheduled-audit.test.ts +377 -0
  160. package/src/scheduler/scheduled-audit.ts +149 -0
  161. package/src/test/integration-test.ts +325 -0
  162. package/src/tools/analyzer.ts +373 -0
  163. package/src/tools/crawl.ts +293 -0
  164. package/src/tools/files.ts +301 -0
  165. package/src/tools/h1-fixer.ts +249 -0
  166. package/src/tools/index.ts +67 -0
  167. package/src/tracking/github-action.ts +326 -0
  168. package/src/tracking/google-analytics.ts +265 -0
  169. package/src/tracking/index.ts +45 -0
  170. package/src/tracking/report-generator.ts +386 -0
  171. package/src/tracking/search-console.ts +335 -0
  172. package/src/types.ts +134 -0
  173. package/src/utils/http.ts +302 -0
  174. package/src/wasm-adapter.ts +297 -0
  175. package/src/wasm-entry.ts +14 -0
  176. package/tsconfig.json +17 -0
  177. package/tsup.wasm.config.ts +26 -0
  178. package/vitest.config.ts +15 -0
@@ -0,0 +1,542 @@
1
+ // Client-Side Rendering Detection - SSR/SSG is critical for SEO
2
+ // Reference: "Technical SEO for Developers - 17 Tips to Rank Higher"
3
+ // "The page should load its content even if I have JavaScript disabled"
4
+ // "Statically generating or server-side rendering is so much safer than rendering only on the client"
5
+
6
+ import * as cheerio from 'cheerio';
7
+ import type { AuditIssue } from '../types.js';
8
+
9
+ export interface RenderingAnalysis {
10
+ renderingMethod: 'ssr' | 'ssg' | 'csr' | 'hybrid' | 'unknown';
11
+ confidence: 'high' | 'medium' | 'low';
12
+ signals: RenderingSignal[];
13
+ frameworkDetected: string | null;
14
+ hasContentInHTML: boolean;
15
+ hasHydrationMarkers: boolean;
16
+ hasClientOnlyIndicators: boolean;
17
+ mainContentCharCount: number;
18
+ recommendations: string[];
19
+ metaManagement: string | null; // React Helmet, Vue Meta, etc.
20
+ hasDynamicMetaTags: boolean;
21
+ // AI-specific content accessibility metrics
22
+ aiAccessibility: {
23
+ htmlContentRatio: number; // % of content in raw HTML vs total expected
24
+ hasSemanticStructure: boolean; // Proper heading hierarchy, landmarks
25
+ keyContentInHTML: boolean; // Title, main headings, first paragraphs in HTML
26
+ aiReadableScore: number; // 0-100 score for AI parsing ability
27
+ };
28
+ }
29
+
30
+ export interface RenderingSignal {
31
+ indicator: string;
32
+ suggests: 'ssr' | 'ssg' | 'csr';
33
+ weight: number;
34
+ }
35
+
36
+ // Framework detection patterns
37
+ const FRAMEWORK_PATTERNS: Record<string, RegExp[]> = {
38
+ 'Next.js': [/__NEXT_DATA__/, /next\//, /_next\//],
39
+ 'Nuxt': [/__NUXT__/, /nuxt/, /_nuxt\//],
40
+ 'Gatsby': [/___gatsby/, /gatsby-/, /gatsby-image/],
41
+ 'Remix': [/__remix/, /remix/],
42
+ 'SvelteKit': [/__sveltekit/, /svelte/],
43
+ 'Angular Universal': [/ng-version/, /angular/],
44
+ 'React': [/react-root/, /data-reactroot/, /__REACT/],
45
+ 'Vue': [/data-v-/, /Vue\./, /__VUE/],
46
+ 'Astro': [/astro-/, /astro:/],
47
+ };
48
+
49
+ // Meta tag management patterns (React Helmet, etc.)
50
+ const META_MANAGEMENT_PATTERNS = [
51
+ { name: 'React Helmet', pattern: /data-react-helmet/i },
52
+ { name: 'Next.js Head', pattern: /__NEXT_DATA__.*"head"/i },
53
+ { name: 'Vue Meta', pattern: /data-vue-meta/i },
54
+ { name: 'Nuxt Head', pattern: /__NUXT__.*"head"/i },
55
+ { name: 'Remix Meta', pattern: /__remix_meta/i },
56
+ ];
57
+
58
+ // Indicators of client-side only rendering (bad for SEO)
59
+ const CSR_INDICATORS = [
60
+ // Empty root elements waiting for JS to populate
61
+ { pattern: /<div id="root"><\/div>/i, weight: 3 },
62
+ { pattern: /<div id="app"><\/div>/i, weight: 3 },
63
+ { pattern: /<div id="__next"><\/div>/i, weight: 2 }, // Empty Next.js (should have content)
64
+ { pattern: /<div id="__nuxt"><\/div>/i, weight: 2 }, // Empty Nuxt
65
+ { pattern: /<main><\/main>/i, weight: 2 },
66
+ { pattern: /<article><\/article>/i, weight: 2 },
67
+
68
+ // Noscript warnings indicating JS dependency
69
+ { pattern: /<noscript>.*(?:enable|require|need).*javascript/i, weight: 3 },
70
+ { pattern: /<noscript>.*(?:won't work|doesn't work)/i, weight: 3 },
71
+
72
+ // Very minimal HTML body
73
+ { pattern: /<body[^>]*>\s*<(?:div|script)[^>]*>\s*<\/(?:div|script)>\s*<\/body>/i, weight: 4 },
74
+
75
+ // Loading spinners/states in initial HTML
76
+ { pattern: /class="[^"]*loading[^"]*"/i, weight: 1 },
77
+ { pattern: /Loading\.\.\./i, weight: 1 },
78
+
79
+ // Client-only component indicators
80
+ { pattern: /data-client-only/i, weight: 2 },
81
+ { pattern: /client:only/i, weight: 2 }, // Astro client:only
82
+ ];
83
+
84
+ // Indicators of server-side rendering (good for SEO)
85
+ const SSR_INDICATORS = [
86
+ // Hydration markers (content was rendered server-side)
87
+ { pattern: /__NEXT_DATA__/, weight: 3 },
88
+ { pattern: /__NUXT__/, weight: 3 },
89
+ { pattern: /data-reactroot/, weight: 2 },
90
+ { pattern: /data-server-rendered/, weight: 3 },
91
+
92
+ // Pre-rendered content indicators
93
+ { pattern: /<h1[^>]*>[^<]+<\/h1>/i, weight: 2 },
94
+ { pattern: /<article[^>]*>[^<]{100,}/i, weight: 3 },
95
+ { pattern: /<main[^>]*>[^<]{100,}/i, weight: 3 },
96
+
97
+ // Meta content (usually server-rendered)
98
+ { pattern: /<meta property="og:title"[^>]*content="[^"]+"/, weight: 1 },
99
+ { pattern: /<meta name="description"[^>]*content="[^"]+"/, weight: 1 },
100
+
101
+ // Structured data
102
+ { pattern: /<script type="application\/ld\+json">/, weight: 2 },
103
+ ];
104
+
105
+ /**
106
+ * Detect framework from HTML
107
+ */
108
+ export function detectFramework(html: string): string | null {
109
+ for (const [framework, patterns] of Object.entries(FRAMEWORK_PATTERNS)) {
110
+ for (const pattern of patterns) {
111
+ if (pattern.test(html)) {
112
+ return framework;
113
+ }
114
+ }
115
+ }
116
+ return null;
117
+ }
118
+
119
+ /**
120
+ * Analyze HTML to determine rendering method
121
+ */
122
+ export function analyzeRendering(html: string): RenderingAnalysis {
123
+ const $ = cheerio.load(html);
124
+ const signals: RenderingSignal[] = [];
125
+
126
+ // Detect framework
127
+ const frameworkDetected = detectFramework(html);
128
+
129
+ // Check for CSR indicators
130
+ let csrScore = 0;
131
+ for (const indicator of CSR_INDICATORS) {
132
+ if (indicator.pattern.test(html)) {
133
+ csrScore += indicator.weight;
134
+ signals.push({
135
+ indicator: indicator.pattern.toString(),
136
+ suggests: 'csr',
137
+ weight: indicator.weight,
138
+ });
139
+ }
140
+ }
141
+
142
+ // Check for SSR indicators
143
+ let ssrScore = 0;
144
+ for (const indicator of SSR_INDICATORS) {
145
+ if (indicator.pattern.test(html)) {
146
+ ssrScore += indicator.weight;
147
+ signals.push({
148
+ indicator: indicator.pattern.toString(),
149
+ suggests: 'ssr',
150
+ weight: indicator.weight,
151
+ });
152
+ }
153
+ }
154
+
155
+ // Analyze main content
156
+ const mainContent = $('main, article, [role="main"], .content, #content').text();
157
+ const bodyText = $('body').text().replace(/\s+/g, ' ').trim();
158
+ const mainContentCharCount = mainContent.length || bodyText.length;
159
+
160
+ // Very little text content is a red flag
161
+ const hasContentInHTML = mainContentCharCount > 200;
162
+ if (!hasContentInHTML) {
163
+ csrScore += 4;
164
+ signals.push({
165
+ indicator: `Body text only ${mainContentCharCount} chars`,
166
+ suggests: 'csr',
167
+ weight: 4,
168
+ });
169
+ } else {
170
+ ssrScore += 2;
171
+ }
172
+
173
+ // Check for hydration markers
174
+ const hasHydrationMarkers =
175
+ /__NEXT_DATA__|__NUXT__|data-reactroot|data-server-rendered/.test(html);
176
+
177
+ // Check for client-only indicators
178
+ const hasClientOnlyIndicators = $('[data-client-only], [client\\:only]').length > 0;
179
+
180
+ // Detect meta tag management library
181
+ let metaManagement: string | null = null;
182
+ for (const { name, pattern } of META_MANAGEMENT_PATTERNS) {
183
+ if (pattern.test(html)) {
184
+ metaManagement = name;
185
+ break;
186
+ }
187
+ }
188
+
189
+ // Check if meta tags appear to be dynamically managed
190
+ const hasDynamicMetaTags = metaManagement !== null ||
191
+ $('meta[data-react-helmet]').length > 0 ||
192
+ $('meta[data-vue-meta]').length > 0;
193
+
194
+ // === AI ACCESSIBILITY ANALYSIS ===
195
+ // AI systems (ChatGPT, Claude, etc.) primarily read raw HTML
196
+ // Content hidden behind JavaScript may not be indexed by AI
197
+
198
+ // Check semantic structure
199
+ const hasH1 = $('h1').length > 0 && $('h1').text().trim().length > 0;
200
+ const hasH2 = $('h2').length > 0;
201
+ const hasMain = $('main, [role="main"]').length > 0;
202
+ const hasArticle = $('article').length > 0;
203
+ const hasSemanticStructure = hasH1 && (hasMain || hasArticle);
204
+
205
+ // Check if key content is in HTML
206
+ const title = $('title').text().trim();
207
+ const h1Text = $('h1').first().text().trim();
208
+ const firstParagraph = $('p').first().text().trim();
209
+
210
+ const keyContentInHTML =
211
+ title.length > 10 &&
212
+ h1Text.length > 5 &&
213
+ firstParagraph.length > 50;
214
+
215
+ // Calculate HTML content ratio
216
+ // Compare actual content to expected minimum for a meaningful page
217
+ const EXPECTED_MIN_CONTENT = 1000; // Minimum expected chars for a content page
218
+ const htmlContentRatio = Math.min(100, (mainContentCharCount / EXPECTED_MIN_CONTENT) * 100);
219
+
220
+ // Calculate AI readable score
221
+ let aiReadableScore = 50; // Base score
222
+
223
+ // Content amount
224
+ if (mainContentCharCount > 2000) aiReadableScore += 20;
225
+ else if (mainContentCharCount > 1000) aiReadableScore += 15;
226
+ else if (mainContentCharCount > 500) aiReadableScore += 10;
227
+ else if (mainContentCharCount < 200) aiReadableScore -= 20;
228
+
229
+ // Semantic structure
230
+ if (hasSemanticStructure) aiReadableScore += 15;
231
+ if (hasH1 && hasH2) aiReadableScore += 5;
232
+
233
+ // Key content in HTML
234
+ if (keyContentInHTML) aiReadableScore += 15;
235
+ else aiReadableScore -= 10;
236
+
237
+ // SSR/SSG bonus
238
+ if (hasHydrationMarkers || ssrScore > csrScore) aiReadableScore += 10;
239
+
240
+ // CSR penalty
241
+ if (csrScore > ssrScore + 3) aiReadableScore -= 20;
242
+
243
+ aiReadableScore = Math.max(0, Math.min(100, aiReadableScore));
244
+
245
+ const aiAccessibility = {
246
+ htmlContentRatio: Math.round(htmlContentRatio),
247
+ hasSemanticStructure,
248
+ keyContentInHTML,
249
+ aiReadableScore,
250
+ };
251
+
252
+ // Determine rendering method
253
+ let renderingMethod: 'ssr' | 'ssg' | 'csr' | 'hybrid' | 'unknown';
254
+ let confidence: 'high' | 'medium' | 'low';
255
+
256
+ if (csrScore > ssrScore + 3) {
257
+ renderingMethod = 'csr';
258
+ confidence = csrScore - ssrScore > 6 ? 'high' : 'medium';
259
+ } else if (ssrScore > csrScore + 3) {
260
+ // Distinguish SSG from SSR (static has specific patterns)
261
+ const isLikelyStatic =
262
+ html.includes('data-gatsby') ||
263
+ html.includes('astro-') ||
264
+ (!html.includes('__NEXT_DATA__') && !html.includes('__NUXT__'));
265
+
266
+ renderingMethod = isLikelyStatic ? 'ssg' : 'ssr';
267
+ confidence = ssrScore - csrScore > 6 ? 'high' : 'medium';
268
+ } else if (hasHydrationMarkers && hasClientOnlyIndicators) {
269
+ renderingMethod = 'hybrid';
270
+ confidence = 'medium';
271
+ } else {
272
+ renderingMethod = 'unknown';
273
+ confidence = 'low';
274
+ }
275
+
276
+ // Generate recommendations
277
+ const recommendations = generateRecommendations(
278
+ renderingMethod,
279
+ hasContentInHTML,
280
+ mainContentCharCount,
281
+ frameworkDetected
282
+ );
283
+
284
+ return {
285
+ renderingMethod,
286
+ confidence,
287
+ signals,
288
+ frameworkDetected,
289
+ hasContentInHTML,
290
+ hasHydrationMarkers,
291
+ hasClientOnlyIndicators,
292
+ mainContentCharCount,
293
+ recommendations,
294
+ metaManagement,
295
+ hasDynamicMetaTags,
296
+ aiAccessibility,
297
+ };
298
+ }
299
+
300
+ function generateRecommendations(
301
+ renderingMethod: string,
302
+ hasContentInHTML: boolean,
303
+ charCount: number,
304
+ framework: string | null
305
+ ): string[] {
306
+ const recommendations: string[] = [];
307
+
308
+ if (renderingMethod === 'csr') {
309
+ recommendations.push(
310
+ 'Critical: Pre-render your pages so crawlers see actual content in the HTML'
311
+ );
312
+
313
+ if (framework === 'React') {
314
+ recommendations.push(
315
+ 'Quick fix: Add react-snap to pre-render pages at build time (npm install -D react-snap, add "postbuild": "react-snap" to scripts)'
316
+ );
317
+ recommendations.push(
318
+ 'Alternative: Use Vike (vite-plugin-ssr) for SSR/SSG without changing frameworks'
319
+ );
320
+ } else if (framework === 'Vue') {
321
+ recommendations.push(
322
+ 'Quick fix: Add prerender-spa-plugin to pre-render pages at build time'
323
+ );
324
+ recommendations.push(
325
+ 'Alternative: Use Vike (vite-plugin-ssr) for SSR/SSG without changing frameworks'
326
+ );
327
+ } else if (framework === 'Angular Universal') {
328
+ recommendations.push(
329
+ 'Enable Angular Universal for server-side rendering'
330
+ );
331
+ } else {
332
+ recommendations.push(
333
+ 'Quick fix: Use a pre-rendering tool like react-snap or prerender-spa-plugin'
334
+ );
335
+ }
336
+
337
+ recommendations.push(
338
+ 'Google can render JavaScript, but pre-rendered HTML is more reliable and faster to index'
339
+ );
340
+ }
341
+
342
+ if (!hasContentInHTML) {
343
+ recommendations.push(
344
+ `Very little content in initial HTML (${charCount} chars). Search engines may not see your content.`
345
+ );
346
+ }
347
+
348
+ if (renderingMethod === 'hybrid') {
349
+ recommendations.push(
350
+ 'Hybrid rendering detected. Ensure critical SEO content is server-rendered, not client-only.'
351
+ );
352
+ }
353
+
354
+ return recommendations;
355
+ }
356
+
357
+ /**
358
+ * Main function: Analyze page rendering method for SEO
359
+ */
360
+ export function analyzeClientRendering(
361
+ html: string,
362
+ url: string
363
+ ): { issues: AuditIssue[]; data: RenderingAnalysis } {
364
+ const $ = cheerio.load(html);
365
+ const issues: AuditIssue[] = [];
366
+ const analysis = analyzeRendering(html);
367
+
368
+ // Critical: Client-side only rendering
369
+ if (analysis.renderingMethod === 'csr' && analysis.confidence !== 'low') {
370
+ const howToFixByFramework = analysis.frameworkDetected === 'React'
371
+ ? 'Add react-snap to pre-render pages: npm install -D react-snap, then add "postbuild": "react-snap" to package.json scripts. No code changes needed.'
372
+ : analysis.frameworkDetected === 'Vue'
373
+ ? 'Add prerender-spa-plugin to pre-render pages at build time. Alternatively, use Vike for SSR/SSG.'
374
+ : 'Pre-render your pages using react-snap, prerender-spa-plugin, or similar build-time tools.';
375
+
376
+ issues.push({
377
+ code: 'CLIENT_SIDE_RENDERING',
378
+ severity: 'error',
379
+ category: 'crawlability',
380
+ title: 'Page relies on client-side rendering',
381
+ description:
382
+ 'This page appears to render content primarily via JavaScript. Search engines may not see your content.',
383
+ impact:
384
+ 'Google can execute JavaScript but it\'s slower and less reliable. Content may not be indexed properly.',
385
+ howToFix: howToFixByFramework,
386
+ affectedUrls: [url],
387
+ details: {
388
+ confidence: analysis.confidence,
389
+ framework: analysis.frameworkDetected,
390
+ signals: analysis.signals.filter(s => s.suggests === 'csr').slice(0, 5),
391
+ },
392
+ });
393
+ }
394
+
395
+ // Warning: Very little content in HTML
396
+ if (!analysis.hasContentInHTML) {
397
+ issues.push({
398
+ code: 'EMPTY_BODY_CONTENT',
399
+ severity: 'error',
400
+ category: 'content',
401
+ title: 'Very little content in initial HTML',
402
+ description:
403
+ `Only ${analysis.mainContentCharCount} characters of text found in the HTML. Content may be loaded via JavaScript.`,
404
+ impact:
405
+ 'Search engines prioritize content in the initial HTML response. JavaScript-loaded content may be missed or delayed.',
406
+ howToFix:
407
+ 'Ensure main page content is present in the server-rendered HTML, not loaded via JavaScript after page load.',
408
+ affectedUrls: [url],
409
+ details: {
410
+ charCount: analysis.mainContentCharCount,
411
+ renderingMethod: analysis.renderingMethod,
412
+ },
413
+ });
414
+ }
415
+
416
+ // Notice: Framework without SSR evidence
417
+ if (
418
+ analysis.frameworkDetected &&
419
+ ['React', 'Vue'].includes(analysis.frameworkDetected) &&
420
+ !analysis.hasHydrationMarkers &&
421
+ analysis.mainContentCharCount < 500
422
+ ) {
423
+ issues.push({
424
+ code: 'SPA_WITHOUT_SSR',
425
+ severity: 'warning',
426
+ category: 'crawlability',
427
+ title: `${analysis.frameworkDetected} detected without SSR markers`,
428
+ description:
429
+ `This appears to be a ${analysis.frameworkDetected} SPA without server-side rendering enabled.`,
430
+ impact:
431
+ 'Single Page Applications without SSR have slower time-to-content for search crawlers.',
432
+ howToFix:
433
+ analysis.frameworkDetected === 'React'
434
+ ? 'Quick fix: Add react-snap (npm install -D react-snap) to pre-render at build time. Alternative: Use Vike for SSR/SSG.'
435
+ : 'Quick fix: Add prerender-spa-plugin to pre-render at build time. Alternative: Use Vike for SSR/SSG.',
436
+ affectedUrls: [url],
437
+ details: {
438
+ framework: analysis.frameworkDetected,
439
+ hasHydrationMarkers: analysis.hasHydrationMarkers,
440
+ },
441
+ });
442
+ }
443
+
444
+ // Notice: Static generation recommended
445
+ if (
446
+ analysis.renderingMethod === 'ssr' &&
447
+ analysis.confidence !== 'low'
448
+ ) {
449
+ // Not an issue, but we could suggest SSG for better performance
450
+ // This is informational only
451
+ }
452
+
453
+ // Warning: React/Vue without meta management library
454
+ if (
455
+ analysis.frameworkDetected &&
456
+ ['React', 'Vue'].includes(analysis.frameworkDetected) &&
457
+ !analysis.hasDynamicMetaTags &&
458
+ analysis.renderingMethod !== 'csr' // Don't double-warn for CSR
459
+ ) {
460
+ const helmetLib = analysis.frameworkDetected === 'React' ? 'React Helmet' : 'Vue Meta';
461
+ const metaTagsPresent = $('meta[name="description"], meta[property="og:title"]').length > 0;
462
+
463
+ if (!metaTagsPresent) {
464
+ issues.push({
465
+ code: 'SPA_NO_META_MANAGEMENT',
466
+ severity: 'warning',
467
+ category: 'on-page',
468
+ title: `${analysis.frameworkDetected} app may lack dynamic meta tag management`,
469
+ description:
470
+ `No ${helmetLib} or similar library detected for managing meta tags in this SPA.`,
471
+ impact:
472
+ 'SPAs need dynamic meta tag management for proper page-specific titles, descriptions, and social tags.',
473
+ howToFix:
474
+ analysis.frameworkDetected === 'React'
475
+ ? 'Use React Helmet, Next.js Head, or Remix meta exports for dynamic meta tags.'
476
+ : 'Use Vue Meta, Nuxt Head, or vue-head for dynamic meta tags.',
477
+ affectedUrls: [url],
478
+ details: {
479
+ framework: analysis.frameworkDetected,
480
+ metaManagement: analysis.metaManagement,
481
+ },
482
+ });
483
+ }
484
+ }
485
+
486
+ // === AI-SPECIFIC CONTENT ACCESSIBILITY CHECKS ===
487
+
488
+ // Low AI readable score
489
+ if (analysis.aiAccessibility.aiReadableScore < 50) {
490
+ issues.push({
491
+ code: 'AI_LOW_HTML_READABILITY',
492
+ severity: 'warning',
493
+ category: 'ai-readiness',
494
+ title: 'Content not optimally accessible to AI systems',
495
+ description: `AI readability score: ${analysis.aiAccessibility.aiReadableScore}/100. AI systems like ChatGPT primarily read raw HTML and may miss JavaScript-rendered content.`,
496
+ impact: 'Content may not be properly indexed by AI search systems (ChatGPT, Perplexity, etc.), reducing AI citation likelihood.',
497
+ howToFix: 'Ensure key content is in the initial HTML response: 1) Use SSR/SSG, 2) Include title, H1, and main content in HTML, 3) Don\'t hide content behind JavaScript interactions.',
498
+ affectedUrls: [url],
499
+ details: {
500
+ aiReadableScore: analysis.aiAccessibility.aiReadableScore,
501
+ htmlContentRatio: analysis.aiAccessibility.htmlContentRatio,
502
+ hasSemanticStructure: analysis.aiAccessibility.hasSemanticStructure,
503
+ keyContentInHTML: analysis.aiAccessibility.keyContentInHTML,
504
+ },
505
+ });
506
+ }
507
+
508
+ // Missing semantic structure for AI
509
+ if (!analysis.aiAccessibility.hasSemanticStructure && analysis.mainContentCharCount > 500) {
510
+ issues.push({
511
+ code: 'AI_NO_SEMANTIC_STRUCTURE',
512
+ severity: 'notice',
513
+ category: 'ai-readiness',
514
+ title: 'Content lacks semantic HTML structure for AI parsing',
515
+ description: 'Missing semantic landmarks (<main>, <article>) or heading hierarchy. AI systems use these to identify and extract key content.',
516
+ impact: 'AI may not correctly identify the main content area, potentially extracting navigation or footer text instead.',
517
+ howToFix: 'Add semantic HTML: wrap main content in <main> or <article>, ensure H1 exists and heading hierarchy is logical (H1 → H2 → H3).',
518
+ affectedUrls: [url],
519
+ });
520
+ }
521
+
522
+ // Key content not in initial HTML
523
+ if (!analysis.aiAccessibility.keyContentInHTML && analysis.renderingMethod !== 'csr') {
524
+ issues.push({
525
+ code: 'AI_KEY_CONTENT_NOT_IN_HTML',
526
+ severity: 'warning',
527
+ category: 'ai-readiness',
528
+ title: 'Key content elements missing from initial HTML',
529
+ description: 'Title, H1, or opening paragraph content is missing or too short in the HTML. AI systems extract these first.',
530
+ impact: 'AI may not have access to your primary message, reducing chances of accurate citation.',
531
+ howToFix: 'Ensure the initial HTML contains: meaningful <title>, descriptive <h1>, and a substantial first paragraph with your key message.',
532
+ affectedUrls: [url],
533
+ details: {
534
+ hasTitle: $('title').text().trim().length > 10,
535
+ hasH1: $('h1').text().trim().length > 5,
536
+ hasFirstParagraph: $('p').first().text().trim().length > 50,
537
+ },
538
+ });
539
+ }
540
+
541
+ return { issues, data: analysis };
542
+ }