@rankcli/agent-runtime 0.0.15 → 0.0.17

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 (203) hide show
  1. package/README.md +5 -4
  2. package/dist/index.d.mts +44 -393
  3. package/dist/index.d.ts +44 -393
  4. package/dist/index.js +22098 -26131
  5. package/dist/index.mjs +11834 -15857
  6. package/package.json +10 -4
  7. package/scripts/build-deno.ts +0 -134
  8. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  9. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  10. package/src/analyzers/geo-analyzer.test.ts +0 -310
  11. package/src/analyzers/geo-analyzer.ts +0 -814
  12. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  13. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  14. package/src/analyzers/index.ts +0 -233
  15. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  16. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  17. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  18. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  19. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  20. package/src/analyzers/security-headers-analyzer.ts +0 -318
  21. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  22. package/src/analyzers/structured-data-analyzer.ts +0 -590
  23. package/src/audit/ai/analyzer.ts +0 -347
  24. package/src/audit/ai/index.ts +0 -29
  25. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  26. package/src/audit/ai/types.ts +0 -179
  27. package/src/audit/checks/additional-checks.ts +0 -439
  28. package/src/audit/checks/agent-experience.ts +0 -108
  29. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  30. package/src/audit/checks/ai-content-structure.ts +0 -325
  31. package/src/audit/checks/ai-readiness.ts +0 -406
  32. package/src/audit/checks/anchor-text.ts +0 -179
  33. package/src/audit/checks/answer-conciseness.ts +0 -322
  34. package/src/audit/checks/asset-minification.ts +0 -270
  35. package/src/audit/checks/bing-optimization.ts +0 -206
  36. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  37. package/src/audit/checks/caching-headers.ts +0 -305
  38. package/src/audit/checks/canonical-advanced.ts +0 -150
  39. package/src/audit/checks/canonical-domain.ts +0 -196
  40. package/src/audit/checks/citation-quality.ts +0 -358
  41. package/src/audit/checks/client-rendering.ts +0 -542
  42. package/src/audit/checks/color-contrast.ts +0 -342
  43. package/src/audit/checks/content-freshness.ts +0 -170
  44. package/src/audit/checks/content-science.ts +0 -589
  45. package/src/audit/checks/conversion-elements.ts +0 -526
  46. package/src/audit/checks/crawlability.ts +0 -220
  47. package/src/audit/checks/directory-listing.ts +0 -172
  48. package/src/audit/checks/dom-analysis.ts +0 -191
  49. package/src/audit/checks/dom-size.ts +0 -246
  50. package/src/audit/checks/duplicate-content.ts +0 -194
  51. package/src/audit/checks/eeat-signals.ts +0 -990
  52. package/src/audit/checks/entity-seo.ts +0 -396
  53. package/src/audit/checks/featured-snippet.ts +0 -473
  54. package/src/audit/checks/freshness-signals.ts +0 -443
  55. package/src/audit/checks/funnel-intent.ts +0 -463
  56. package/src/audit/checks/hreflang.ts +0 -174
  57. package/src/audit/checks/html-compliance.ts +0 -302
  58. package/src/audit/checks/image-dimensions.ts +0 -167
  59. package/src/audit/checks/images.ts +0 -160
  60. package/src/audit/checks/indexnow.ts +0 -275
  61. package/src/audit/checks/interactive-tools.ts +0 -475
  62. package/src/audit/checks/internal-link-graph.ts +0 -436
  63. package/src/audit/checks/keyword-analysis.ts +0 -239
  64. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  65. package/src/audit/checks/keyword-placement.ts +0 -471
  66. package/src/audit/checks/links.ts +0 -273
  67. package/src/audit/checks/llms-txt.ts +0 -224
  68. package/src/audit/checks/local-seo.ts +0 -296
  69. package/src/audit/checks/mobile.ts +0 -167
  70. package/src/audit/checks/modern-images.ts +0 -226
  71. package/src/audit/checks/navboost-signals.ts +0 -395
  72. package/src/audit/checks/on-page.ts +0 -209
  73. package/src/audit/checks/page-resources.ts +0 -285
  74. package/src/audit/checks/pagination.ts +0 -180
  75. package/src/audit/checks/performance.ts +0 -153
  76. package/src/audit/checks/platform-presence.ts +0 -580
  77. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  78. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  79. package/src/audit/checks/redirect-analysis.ts +0 -153
  80. package/src/audit/checks/redirect-chain.ts +0 -389
  81. package/src/audit/checks/resource-hints.ts +0 -420
  82. package/src/audit/checks/responsive-css.ts +0 -247
  83. package/src/audit/checks/responsive-images.ts +0 -396
  84. package/src/audit/checks/review-ecosystem.ts +0 -415
  85. package/src/audit/checks/robots-validation.ts +0 -373
  86. package/src/audit/checks/security-headers.ts +0 -188
  87. package/src/audit/checks/security.ts +0 -144
  88. package/src/audit/checks/serp-preview.ts +0 -251
  89. package/src/audit/checks/site-maturity.ts +0 -453
  90. package/src/audit/checks/social-meta.test.ts +0 -275
  91. package/src/audit/checks/social-meta.ts +0 -134
  92. package/src/audit/checks/soft-404.ts +0 -151
  93. package/src/audit/checks/structured-data.ts +0 -238
  94. package/src/audit/checks/tech-detection.ts +0 -496
  95. package/src/audit/checks/topical-clusters.ts +0 -435
  96. package/src/audit/checks/tracker-bloat.ts +0 -462
  97. package/src/audit/checks/tracking-verification.test.ts +0 -371
  98. package/src/audit/checks/tracking-verification.ts +0 -636
  99. package/src/audit/checks/url-safety.ts +0 -682
  100. package/src/audit/deno-entry.ts +0 -66
  101. package/src/audit/discovery/index.ts +0 -15
  102. package/src/audit/discovery/link-crawler.ts +0 -233
  103. package/src/audit/discovery/repo-routes.ts +0 -347
  104. package/src/audit/engine.ts +0 -633
  105. package/src/audit/fixes/index.ts +0 -209
  106. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  107. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  108. package/src/audit/index.ts +0 -74
  109. package/src/audit/runner.test.ts +0 -299
  110. package/src/audit/runner.ts +0 -130
  111. package/src/audit/types.ts +0 -1987
  112. package/src/content/featured-snippet.ts +0 -367
  113. package/src/content/generator.test.ts +0 -534
  114. package/src/content/generator.ts +0 -501
  115. package/src/content/headline.ts +0 -317
  116. package/src/content/index.ts +0 -62
  117. package/src/content/intent.ts +0 -258
  118. package/src/content/keyword-density.ts +0 -349
  119. package/src/content/readability.ts +0 -262
  120. package/src/executor.ts +0 -336
  121. package/src/fixer/framework-fixes.test.ts +0 -489
  122. package/src/fixer/framework-fixes.ts +0 -5287
  123. package/src/fixer/index.ts +0 -6
  124. package/src/fixer/schemas.ts +0 -971
  125. package/src/fixer.ts +0 -642
  126. package/src/frameworks/detector.test.ts +0 -248
  127. package/src/frameworks/detector.ts +0 -899
  128. package/src/frameworks/index.ts +0 -68
  129. package/src/frameworks/recipes/angular.yaml +0 -171
  130. package/src/frameworks/recipes/astro.yaml +0 -206
  131. package/src/frameworks/recipes/django.yaml +0 -180
  132. package/src/frameworks/recipes/laravel.yaml +0 -137
  133. package/src/frameworks/recipes/nextjs.yaml +0 -268
  134. package/src/frameworks/recipes/nuxt.yaml +0 -175
  135. package/src/frameworks/recipes/rails.yaml +0 -188
  136. package/src/frameworks/recipes/react.yaml +0 -202
  137. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  138. package/src/frameworks/recipes/vue.yaml +0 -137
  139. package/src/frameworks/recipes/wordpress.yaml +0 -209
  140. package/src/frameworks/suggestion-engine.ts +0 -357
  141. package/src/geo/geo-content.test.ts +0 -305
  142. package/src/geo/geo-content.ts +0 -266
  143. package/src/geo/geo-history.test.ts +0 -473
  144. package/src/geo/geo-history.ts +0 -433
  145. package/src/geo/geo-tracker.test.ts +0 -359
  146. package/src/geo/geo-tracker.ts +0 -411
  147. package/src/geo/index.ts +0 -11
  148. package/src/geo/llm-citation-checker.ts +0 -188
  149. package/src/git/commit-helper.test.ts +0 -261
  150. package/src/git/commit-helper.ts +0 -329
  151. package/src/git/index.ts +0 -12
  152. package/src/git/pr-helper.test.ts +0 -284
  153. package/src/git/pr-helper.ts +0 -307
  154. package/src/index.ts +0 -76
  155. package/src/keywords/ai-keyword-engine.ts +0 -1062
  156. package/src/keywords/ai-summarizer.ts +0 -387
  157. package/src/keywords/ci-mode.ts +0 -555
  158. package/src/keywords/engine.ts +0 -359
  159. package/src/keywords/index.ts +0 -151
  160. package/src/keywords/llm-judge.ts +0 -357
  161. package/src/keywords/nlp-analysis.ts +0 -706
  162. package/src/keywords/prioritizer.ts +0 -295
  163. package/src/keywords/site-crawler.ts +0 -342
  164. package/src/keywords/sources/autocomplete.ts +0 -139
  165. package/src/keywords/sources/competitive-search.ts +0 -450
  166. package/src/keywords/sources/competitor-analysis.ts +0 -374
  167. package/src/keywords/sources/dataforseo.ts +0 -206
  168. package/src/keywords/sources/free-sources.ts +0 -294
  169. package/src/keywords/sources/gsc.ts +0 -123
  170. package/src/keywords/topic-grouping.ts +0 -327
  171. package/src/keywords/types.ts +0 -144
  172. package/src/keywords/wizard.ts +0 -457
  173. package/src/loader.ts +0 -40
  174. package/src/ranking/index.ts +0 -5
  175. package/src/ranking/serp-client.ts +0 -348
  176. package/src/ranking/tracker.ts +0 -380
  177. package/src/ranking/types.ts +0 -123
  178. package/src/reports/index.ts +0 -7
  179. package/src/reports/report-generator.test.ts +0 -293
  180. package/src/reports/report-generator.ts +0 -713
  181. package/src/scheduler/alerts.test.ts +0 -458
  182. package/src/scheduler/alerts.ts +0 -328
  183. package/src/scheduler/index.ts +0 -8
  184. package/src/scheduler/scheduled-audit.test.ts +0 -377
  185. package/src/scheduler/scheduled-audit.ts +0 -149
  186. package/src/test/integration-test.ts +0 -325
  187. package/src/tools/analyzer.ts +0 -373
  188. package/src/tools/crawl.ts +0 -293
  189. package/src/tools/files.ts +0 -301
  190. package/src/tools/h1-fixer.ts +0 -249
  191. package/src/tools/index.ts +0 -67
  192. package/src/tracking/github-action.ts +0 -326
  193. package/src/tracking/google-analytics.ts +0 -265
  194. package/src/tracking/index.ts +0 -45
  195. package/src/tracking/report-generator.ts +0 -386
  196. package/src/tracking/search-console.ts +0 -335
  197. package/src/types.ts +0 -148
  198. package/src/utils/http.ts +0 -302
  199. package/src/wasm-adapter.ts +0 -297
  200. package/src/wasm-entry.ts +0 -14
  201. package/tsconfig.json +0 -17
  202. package/tsup.wasm.config.ts +0 -26
  203. package/vitest.config.ts +0 -15
@@ -1,285 +0,0 @@
1
- /**
2
- * Page Resources Check (Page Objects Analysis)
3
- *
4
- * Analyzes the number and types of embedded resources on a page.
5
- * Too many HTTP requests slow down page load significantly due to:
6
- * - Connection overhead (DNS, TCP, TLS)
7
- * - Browser connection limits per domain
8
- * - Render blocking
9
- *
10
- * Best practices:
11
- * - Keep total requests under 50 for optimal performance
12
- * - Minimize third-party resources
13
- * - Combine/bundle CSS and JS where possible
14
- */
15
-
16
- import * as cheerio from 'cheerio';
17
- import type { AuditIssue } from '../types.js';
18
-
19
- export interface PageResourcesData {
20
- total: number;
21
- byType: {
22
- stylesheets: number;
23
- scripts: number;
24
- images: number;
25
- fonts: number;
26
- iframes: number;
27
- other: number;
28
- };
29
- byOrigin: {
30
- firstParty: number;
31
- thirdParty: number;
32
- };
33
- thirdPartyDomains: string[];
34
- details: {
35
- stylesheets: string[];
36
- scripts: string[];
37
- images: string[];
38
- fonts: string[];
39
- iframes: string[];
40
- };
41
- }
42
-
43
- /**
44
- * Analyze page resources
45
- */
46
- export function analyzePageResources(html: string, url: string): { issues: AuditIssue[]; data: PageResourcesData } {
47
- const issues: AuditIssue[] = [];
48
- const $ = cheerio.load(html);
49
- const baseUrl = new URL(url);
50
- const baseHostname = baseUrl.hostname;
51
-
52
- const stylesheets: string[] = [];
53
- const scripts: string[] = [];
54
- const images: string[] = [];
55
- const fonts: string[] = [];
56
- const iframes: string[] = [];
57
- const thirdPartyDomains = new Set<string>();
58
-
59
- let firstParty = 0;
60
- let thirdParty = 0;
61
-
62
- /**
63
- * Check if URL is first-party
64
- */
65
- function isFirstParty(resourceUrl: string): boolean {
66
- try {
67
- const resourceHostname = new URL(resourceUrl, url).hostname;
68
- // Consider same domain or subdomains as first-party
69
- return resourceHostname === baseHostname || resourceHostname.endsWith(`.${baseHostname}`);
70
- } catch {
71
- return true; // Relative URLs are first-party
72
- }
73
- }
74
-
75
- /**
76
- * Track resource origin
77
- */
78
- function trackOrigin(resourceUrl: string): void {
79
- if (isFirstParty(resourceUrl)) {
80
- firstParty++;
81
- } else {
82
- thirdParty++;
83
- try {
84
- const domain = new URL(resourceUrl, url).hostname;
85
- thirdPartyDomains.add(domain);
86
- } catch {
87
- // Invalid URL
88
- }
89
- }
90
- }
91
-
92
- // Extract stylesheets
93
- $('link[rel="stylesheet"][href]').each((_, el) => {
94
- const href = $(el).attr('href');
95
- if (href && !href.startsWith('data:')) {
96
- stylesheets.push(href);
97
- trackOrigin(href);
98
- }
99
- });
100
-
101
- // Extract scripts
102
- $('script[src]').each((_, el) => {
103
- const src = $(el).attr('src');
104
- if (src && !src.startsWith('data:')) {
105
- scripts.push(src);
106
- trackOrigin(src);
107
- }
108
- });
109
-
110
- // Extract images
111
- $('img[src]').each((_, el) => {
112
- const src = $(el).attr('src');
113
- if (src && !src.startsWith('data:')) {
114
- images.push(src);
115
- trackOrigin(src);
116
- }
117
- });
118
-
119
- // Also check srcset for responsive images
120
- $('img[srcset], source[srcset]').each((_, el) => {
121
- const srcset = $(el).attr('srcset');
122
- if (srcset) {
123
- // Parse srcset - format: "url1 1x, url2 2x" or "url1 300w, url2 600w"
124
- const urls = srcset.split(',').map((s) => s.trim().split(/\s+/)[0]);
125
- for (const srcUrl of urls) {
126
- if (srcUrl && !srcUrl.startsWith('data:') && !images.includes(srcUrl)) {
127
- images.push(srcUrl);
128
- trackOrigin(srcUrl);
129
- }
130
- }
131
- }
132
- });
133
-
134
- // Extract fonts (preloaded or linked)
135
- $('link[rel="preload"][as="font"], link[href*=".woff"], link[href*=".woff2"], link[href*=".ttf"], link[href*=".otf"]').each(
136
- (_, el) => {
137
- const href = $(el).attr('href');
138
- if (href && !href.startsWith('data:')) {
139
- fonts.push(href);
140
- trackOrigin(href);
141
- }
142
- }
143
- );
144
-
145
- // Extract iframes
146
- $('iframe[src]').each((_, el) => {
147
- const src = $(el).attr('src');
148
- if (src && !src.startsWith('about:') && !src.startsWith('javascript:')) {
149
- iframes.push(src);
150
- trackOrigin(src);
151
- }
152
- });
153
-
154
- // Calculate other resources (preloads, prefetches that aren't already counted)
155
- let other = 0;
156
- $('link[rel="preload"], link[rel="prefetch"], link[rel="modulepreload"]').each((_, el) => {
157
- const href = $(el).attr('href');
158
- const as = $(el).attr('as');
159
- if (href && !href.startsWith('data:')) {
160
- // Don't double-count fonts and stylesheets
161
- if (as !== 'font' && as !== 'style' && !stylesheets.includes(href) && !fonts.includes(href)) {
162
- other++;
163
- trackOrigin(href);
164
- }
165
- }
166
- });
167
-
168
- const total = stylesheets.length + scripts.length + images.length + fonts.length + iframes.length + other;
169
-
170
- // Generate issues
171
- if (total > 100) {
172
- issues.push({
173
- code: 'PAGE_RESOURCES_EXCESSIVE',
174
- severity: 'error',
175
- category: 'performance',
176
- title: 'Excessive number of page resources',
177
- description: `Page requests ${total} resources. This significantly impacts load time due to connection overhead and browser limits.`,
178
- impact:
179
- 'Too many HTTP requests cause slow page loads, poor Core Web Vitals, and high bounce rates. Each request has DNS, TCP, and TLS overhead.',
180
- howToFix:
181
- 'Combine CSS/JS files, use image sprites or inline small images, lazy-load non-critical resources, remove unused dependencies.',
182
- affectedUrls: [url],
183
- details: {
184
- total,
185
- breakdown: {
186
- stylesheets: stylesheets.length,
187
- scripts: scripts.length,
188
- images: images.length,
189
- fonts: fonts.length,
190
- iframes: iframes.length,
191
- other,
192
- },
193
- recommendation: 'Aim for under 50 total requests for optimal performance.',
194
- },
195
- });
196
- } else if (total > 50) {
197
- issues.push({
198
- code: 'PAGE_RESOURCES_HIGH',
199
- severity: 'warning',
200
- category: 'performance',
201
- title: 'High number of page resources',
202
- description: `Page requests ${total} resources. Consider reducing for better performance.`,
203
- impact: 'Many HTTP requests increase page load time, especially on mobile networks.',
204
- howToFix: 'Bundle CSS/JS files, lazy-load images below the fold, consider critical CSS inlining.',
205
- affectedUrls: [url],
206
- details: {
207
- total,
208
- breakdown: {
209
- stylesheets: stylesheets.length,
210
- scripts: scripts.length,
211
- images: images.length,
212
- fonts: fonts.length,
213
- iframes: iframes.length,
214
- other,
215
- },
216
- },
217
- });
218
- }
219
-
220
- // Check third-party resources
221
- if (thirdParty > 20) {
222
- issues.push({
223
- code: 'PAGE_RESOURCES_THIRD_PARTY_HIGH',
224
- severity: 'warning',
225
- category: 'performance',
226
- title: 'Many third-party resources',
227
- description: `Page loads ${thirdParty} resources from ${thirdPartyDomains.size} third-party domains.`,
228
- impact:
229
- 'Third-party resources are outside your control and add latency. They can also be a privacy/security concern.',
230
- howToFix:
231
- 'Self-host critical third-party resources when possible. Use preconnect hints for remaining third-party origins.',
232
- affectedUrls: [url],
233
- details: {
234
- thirdPartyCount: thirdParty,
235
- domains: Array.from(thirdPartyDomains).slice(0, 10),
236
- },
237
- });
238
- }
239
-
240
- // Check for too many iframes
241
- if (iframes.length > 3) {
242
- issues.push({
243
- code: 'PAGE_RESOURCES_MANY_IFRAMES',
244
- severity: 'warning',
245
- category: 'performance',
246
- title: 'Multiple iframes detected',
247
- description: `Page contains ${iframes.length} iframes. Each iframe loads its own document and resources.`,
248
- impact: 'Iframes significantly increase page weight and can block the main thread.',
249
- howToFix:
250
- 'Lazy-load iframes that are below the fold. Consider native embeds or facade patterns for video/widget iframes.',
251
- affectedUrls: [url],
252
- details: {
253
- iframeCount: iframes.length,
254
- iframes: iframes.slice(0, 5),
255
- },
256
- });
257
- }
258
-
259
- return {
260
- issues,
261
- data: {
262
- total,
263
- byType: {
264
- stylesheets: stylesheets.length,
265
- scripts: scripts.length,
266
- images: images.length,
267
- fonts: fonts.length,
268
- iframes: iframes.length,
269
- other,
270
- },
271
- byOrigin: {
272
- firstParty,
273
- thirdParty,
274
- },
275
- thirdPartyDomains: Array.from(thirdPartyDomains),
276
- details: {
277
- stylesheets,
278
- scripts,
279
- images: images.slice(0, 20), // Limit for data size
280
- fonts,
281
- iframes,
282
- },
283
- },
284
- };
285
- }
@@ -1,180 +0,0 @@
1
- import * as cheerio from 'cheerio';
2
- import type { AuditIssue } from '../types.js';
3
- import { ISSUE_DEFINITIONS } from '../types.js';
4
-
5
- export interface PaginationData {
6
- hasPagination: boolean;
7
- hasHtmlPaginationLinks: boolean;
8
- hasInfiniteScroll: boolean;
9
- hasLoadMoreButton: boolean;
10
- paginationLinks: string[];
11
- relNextPrev: {
12
- hasNext: boolean;
13
- hasPrev: boolean;
14
- nextUrl?: string;
15
- prevUrl?: string;
16
- };
17
- currentPage?: number;
18
- totalPages?: number;
19
- }
20
-
21
- export function analyzePagination(
22
- html: string,
23
- url: string,
24
- canonical?: string
25
- ): { issues: AuditIssue[]; data: PaginationData } {
26
- const issues: AuditIssue[] = [];
27
- const $ = cheerio.load(html);
28
-
29
- // Check for rel="next" and rel="prev"
30
- const nextLink = $('link[rel="next"]').attr('href');
31
- const prevLink = $('link[rel="prev"]').attr('href');
32
-
33
- // Detect pagination patterns in links
34
- const paginationLinks: string[] = [];
35
- const paginationPatterns = [
36
- /[?&]page=\d+/,
37
- /[?&]p=\d+/,
38
- /\/page\/\d+/,
39
- /\/p\/\d+/,
40
- /-page-\d+/,
41
- /\/\d+\/?$/,
42
- ];
43
-
44
- $('a[href]').each((_, el) => {
45
- const href = $(el).attr('href') || '';
46
- for (const pattern of paginationPatterns) {
47
- if (pattern.test(href)) {
48
- try {
49
- const fullUrl = new URL(href, url).href;
50
- if (!paginationLinks.includes(fullUrl)) {
51
- paginationLinks.push(fullUrl);
52
- }
53
- } catch {
54
- // Invalid URL, skip
55
- }
56
- break;
57
- }
58
- }
59
- });
60
-
61
- // Detect infinite scroll patterns
62
- const hasInfiniteScrollScript = html.includes('infinite-scroll') ||
63
- html.includes('infiniteScroll') ||
64
- html.includes('infinite_scroll') ||
65
- $('[data-infinite-scroll]').length > 0 ||
66
- $('[data-infinite]').length > 0 ||
67
- $('.infinite-scroll').length > 0;
68
-
69
- // Detect "load more" buttons
70
- const loadMoreSelectors = [
71
- 'button:contains("Load More")',
72
- 'button:contains("Load more")',
73
- 'button:contains("Show More")',
74
- 'button:contains("Show more")',
75
- 'a:contains("Load More")',
76
- 'a:contains("Load more")',
77
- '[class*="load-more"]',
78
- '[class*="loadmore"]',
79
- '[data-load-more]',
80
- ];
81
-
82
- let hasLoadMoreButton = false;
83
- for (const selector of loadMoreSelectors) {
84
- try {
85
- if ($(selector).length > 0) {
86
- hasLoadMoreButton = true;
87
- break;
88
- }
89
- } catch {
90
- // Invalid selector, skip
91
- }
92
- }
93
-
94
- // Try to detect current page number
95
- let currentPage: number | undefined;
96
- let totalPages: number | undefined;
97
-
98
- // Check URL for page number
99
- const pageMatch = url.match(/[?&]page=(\d+)|\/page\/(\d+)|[?&]p=(\d+)/);
100
- if (pageMatch) {
101
- currentPage = parseInt(pageMatch[1] || pageMatch[2] || pageMatch[3], 10);
102
- }
103
-
104
- // Check for "Page X of Y" pattern
105
- const pageOfPattern = /page\s*(\d+)\s*of\s*(\d+)/i;
106
- const pageOfMatch = $('body').text().match(pageOfPattern);
107
- if (pageOfMatch) {
108
- currentPage = parseInt(pageOfMatch[1], 10);
109
- totalPages = parseInt(pageOfMatch[2], 10);
110
- }
111
-
112
- const hasPagination = paginationLinks.length > 0 ||
113
- nextLink !== undefined ||
114
- prevLink !== undefined ||
115
- currentPage !== undefined;
116
-
117
- const hasHtmlPaginationLinks = paginationLinks.length > 0;
118
-
119
- const data: PaginationData = {
120
- hasPagination,
121
- hasHtmlPaginationLinks,
122
- hasInfiniteScroll: hasInfiniteScrollScript,
123
- hasLoadMoreButton,
124
- paginationLinks,
125
- relNextPrev: {
126
- hasNext: !!nextLink,
127
- hasPrev: !!prevLink,
128
- nextUrl: nextLink,
129
- prevUrl: prevLink,
130
- },
131
- currentPage,
132
- totalPages,
133
- };
134
-
135
- // ==================== Issue Detection ====================
136
-
137
- // Infinite scroll without HTML fallback links
138
- if (hasInfiniteScrollScript && !hasHtmlPaginationLinks) {
139
- issues.push({
140
- ...ISSUE_DEFINITIONS.INFINITE_SCROLL_NO_FALLBACK,
141
- affectedUrls: [url],
142
- details: {
143
- hasLoadMore: hasLoadMoreButton,
144
- suggestion: 'Add <a href> pagination links alongside infinite scroll for SEO',
145
- },
146
- });
147
- }
148
-
149
- // Load more without HTML links
150
- if (hasLoadMoreButton && !hasHtmlPaginationLinks && !hasInfiniteScrollScript) {
151
- issues.push({
152
- ...ISSUE_DEFINITIONS.PAGINATION_NO_LINKS,
153
- affectedUrls: [url],
154
- details: {
155
- suggestion: 'Ensure "Load More" button also has underlying <a> links',
156
- },
157
- });
158
- }
159
-
160
- // Check for improper canonical on paginated pages
161
- if (hasPagination && currentPage && currentPage > 1 && canonical) {
162
- // Check if canonical points to page 1
163
- const isCanonicalToPage1 = !paginationPatterns.some(p => p.test(canonical));
164
- const urlHasPageNumber = paginationPatterns.some(p => p.test(url));
165
-
166
- if (isCanonicalToPage1 && urlHasPageNumber) {
167
- issues.push({
168
- ...ISSUE_DEFINITIONS.PAGINATION_CANONICAL_ISSUE,
169
- affectedUrls: [url],
170
- details: {
171
- currentPage,
172
- canonical,
173
- suggestion: 'Paginated pages should self-reference or point to a View All page',
174
- },
175
- });
176
- }
177
- }
178
-
179
- return { issues, data };
180
- }
@@ -1,153 +0,0 @@
1
- import { httpGet, httpPost } from '../../utils/http.js';
2
- import type { AuditIssue } from '../types.js';
3
- import { ISSUE_DEFINITIONS } from '../types.js';
4
-
5
- export interface PerformanceData {
6
- loadTime: number; // ms
7
- ttfb: number; // ms
8
- htmlSize: number; // bytes
9
- compressed: boolean;
10
- cacheControl?: string;
11
- contentEncoding?: string;
12
- }
13
-
14
- export async function analyzePerformance(url: string): Promise<{ issues: AuditIssue[]; data: PerformanceData }> {
15
- const issues: AuditIssue[] = [];
16
-
17
- const startTime = Date.now();
18
-
19
- try {
20
- const response = await httpGet<string>(url, {
21
- headers: {
22
- 'Accept-Encoding': 'gzip, deflate, br',
23
- },
24
- timeout: 30000,
25
- validateStatus: () => true,
26
- });
27
-
28
- const loadTime = Date.now() - startTime;
29
- // Note: TTFB approximation - fetch doesn't expose this directly
30
- const ttfbTime = Math.min(loadTime, loadTime * 0.3); // Estimate ~30% of total
31
- const htmlSize = typeof response.data === 'string' ? response.data.length : 0;
32
- const contentEncoding = response.headers['content-encoding'];
33
- const cacheControl = response.headers['cache-control'];
34
- const compressed = !!contentEncoding && ['gzip', 'deflate', 'br'].some(e => contentEncoding.includes(e));
35
-
36
- const data: PerformanceData = {
37
- loadTime,
38
- ttfb: ttfbTime || loadTime,
39
- htmlSize,
40
- compressed,
41
- cacheControl,
42
- contentEncoding,
43
- };
44
-
45
- // Check load time
46
- if (loadTime > 3000) {
47
- issues.push({
48
- ...ISSUE_DEFINITIONS.SLOW_PAGE,
49
- affectedUrls: [url],
50
- details: { loadTime: `${(loadTime / 1000).toFixed(1)}s` },
51
- });
52
- }
53
-
54
- // Check TTFB
55
- if (ttfbTime > 600) {
56
- issues.push({
57
- ...ISSUE_DEFINITIONS.SLOW_TTFB,
58
- affectedUrls: [url],
59
- details: { ttfb: `${ttfbTime}ms` },
60
- });
61
- }
62
-
63
- // Check HTML size
64
- if (htmlSize > 100 * 1024) { // > 100KB
65
- issues.push({
66
- ...ISSUE_DEFINITIONS.HTML_TOO_LARGE,
67
- affectedUrls: [url],
68
- details: { size: `${(htmlSize / 1024).toFixed(0)}KB` },
69
- });
70
- }
71
-
72
- // Check compression
73
- if (!compressed && htmlSize > 1024) {
74
- issues.push({
75
- ...ISSUE_DEFINITIONS.UNCOMPRESSED,
76
- affectedUrls: [url],
77
- details: { htmlSize: `${(htmlSize / 1024).toFixed(0)}KB` },
78
- });
79
- }
80
-
81
- // Check cache headers
82
- if (!cacheControl) {
83
- issues.push({
84
- ...ISSUE_DEFINITIONS.NO_CACHE,
85
- affectedUrls: [url],
86
- });
87
- }
88
-
89
- return { issues, data };
90
- } catch (error) {
91
- return {
92
- issues: [{
93
- ...ISSUE_DEFINITIONS.SLOW_PAGE,
94
- affectedUrls: [url],
95
- details: { error: error instanceof Error ? error.message : 'Request failed' },
96
- }],
97
- data: {
98
- loadTime: 0,
99
- ttfb: 0,
100
- htmlSize: 0,
101
- compressed: false,
102
- }
103
- };
104
- }
105
- }
106
-
107
- // Fetch Core Web Vitals from CrUX API (requires API key)
108
- export async function fetchCoreWebVitals(url: string, apiKey?: string): Promise<{
109
- lcp?: { value: number; rating: 'good' | 'needs-improvement' | 'poor' };
110
- fid?: { value: number; rating: 'good' | 'needs-improvement' | 'poor' };
111
- cls?: { value: number; rating: 'good' | 'needs-improvement' | 'poor' };
112
- inp?: { value: number; rating: 'good' | 'needs-improvement' | 'poor' };
113
- } | null> {
114
- if (!apiKey) return null;
115
-
116
- try {
117
- const response = await httpPost<{ record?: { metrics?: Record<string, { percentiles?: { p75?: number } }> } }>(
118
- `https://chromeuxreport.googleapis.com/v1/records:queryRecord?key=${apiKey}`,
119
- { url },
120
- { timeout: 10000 }
121
- );
122
-
123
- const metrics = response.data?.record?.metrics;
124
- if (!metrics) return null;
125
-
126
- const getRating = (value: number, thresholds: [number, number]): 'good' | 'needs-improvement' | 'poor' => {
127
- if (value <= thresholds[0]) return 'good';
128
- if (value <= thresholds[1]) return 'needs-improvement';
129
- return 'poor';
130
- };
131
-
132
- return {
133
- lcp: metrics.largest_contentful_paint?.percentiles?.p75 ? {
134
- value: metrics.largest_contentful_paint.percentiles.p75,
135
- rating: getRating(metrics.largest_contentful_paint.percentiles.p75, [2500, 4000]),
136
- } : undefined,
137
- fid: metrics.first_input_delay?.percentiles?.p75 ? {
138
- value: metrics.first_input_delay.percentiles.p75,
139
- rating: getRating(metrics.first_input_delay.percentiles.p75, [100, 300]),
140
- } : undefined,
141
- cls: metrics.cumulative_layout_shift?.percentiles?.p75 ? {
142
- value: metrics.cumulative_layout_shift.percentiles.p75,
143
- rating: getRating(metrics.cumulative_layout_shift.percentiles.p75, [0.1, 0.25]),
144
- } : undefined,
145
- inp: metrics.interaction_to_next_paint?.percentiles?.p75 ? {
146
- value: metrics.interaction_to_next_paint.percentiles.p75,
147
- rating: getRating(metrics.interaction_to_next_paint.percentiles.p75, [200, 500]),
148
- } : undefined,
149
- };
150
- } catch {
151
- return null;
152
- }
153
- }