@rankcli/agent-runtime 0.0.14 → 0.0.16

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 (199) hide show
  1. package/dist/index.d.mts +77 -393
  2. package/dist/index.d.ts +77 -393
  3. package/dist/index.js +417 -6443
  4. package/dist/index.mjs +296 -6313
  5. package/package.json +6 -1
  6. package/scripts/build-deno.ts +0 -134
  7. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  8. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  9. package/src/analyzers/geo-analyzer.test.ts +0 -310
  10. package/src/analyzers/geo-analyzer.ts +0 -814
  11. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  12. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  13. package/src/analyzers/index.ts +0 -233
  14. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  15. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  16. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  17. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  18. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  19. package/src/analyzers/security-headers-analyzer.ts +0 -318
  20. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  21. package/src/analyzers/structured-data-analyzer.ts +0 -590
  22. package/src/audit/ai/analyzer.ts +0 -347
  23. package/src/audit/ai/index.ts +0 -29
  24. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  25. package/src/audit/ai/types.ts +0 -179
  26. package/src/audit/checks/additional-checks.ts +0 -439
  27. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  28. package/src/audit/checks/ai-content-structure.ts +0 -325
  29. package/src/audit/checks/ai-readiness.ts +0 -339
  30. package/src/audit/checks/anchor-text.ts +0 -179
  31. package/src/audit/checks/answer-conciseness.ts +0 -322
  32. package/src/audit/checks/asset-minification.ts +0 -270
  33. package/src/audit/checks/bing-optimization.ts +0 -206
  34. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  35. package/src/audit/checks/caching-headers.ts +0 -305
  36. package/src/audit/checks/canonical-advanced.ts +0 -150
  37. package/src/audit/checks/canonical-domain.ts +0 -196
  38. package/src/audit/checks/citation-quality.ts +0 -358
  39. package/src/audit/checks/client-rendering.ts +0 -542
  40. package/src/audit/checks/color-contrast.ts +0 -342
  41. package/src/audit/checks/content-freshness.ts +0 -170
  42. package/src/audit/checks/content-science.ts +0 -589
  43. package/src/audit/checks/conversion-elements.ts +0 -526
  44. package/src/audit/checks/crawlability.ts +0 -220
  45. package/src/audit/checks/directory-listing.ts +0 -172
  46. package/src/audit/checks/dom-analysis.ts +0 -191
  47. package/src/audit/checks/dom-size.ts +0 -246
  48. package/src/audit/checks/duplicate-content.ts +0 -194
  49. package/src/audit/checks/eeat-signals.ts +0 -990
  50. package/src/audit/checks/entity-seo.ts +0 -396
  51. package/src/audit/checks/featured-snippet.ts +0 -473
  52. package/src/audit/checks/freshness-signals.ts +0 -443
  53. package/src/audit/checks/funnel-intent.ts +0 -463
  54. package/src/audit/checks/hreflang.ts +0 -174
  55. package/src/audit/checks/html-compliance.ts +0 -302
  56. package/src/audit/checks/image-dimensions.ts +0 -167
  57. package/src/audit/checks/images.ts +0 -160
  58. package/src/audit/checks/indexnow.ts +0 -275
  59. package/src/audit/checks/interactive-tools.ts +0 -475
  60. package/src/audit/checks/internal-link-graph.ts +0 -436
  61. package/src/audit/checks/keyword-analysis.ts +0 -239
  62. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  63. package/src/audit/checks/keyword-placement.ts +0 -471
  64. package/src/audit/checks/links.ts +0 -273
  65. package/src/audit/checks/llms-txt.ts +0 -224
  66. package/src/audit/checks/local-seo.ts +0 -296
  67. package/src/audit/checks/mobile.ts +0 -167
  68. package/src/audit/checks/modern-images.ts +0 -226
  69. package/src/audit/checks/navboost-signals.ts +0 -395
  70. package/src/audit/checks/on-page.ts +0 -209
  71. package/src/audit/checks/page-resources.ts +0 -285
  72. package/src/audit/checks/pagination.ts +0 -180
  73. package/src/audit/checks/performance.ts +0 -153
  74. package/src/audit/checks/platform-presence.ts +0 -580
  75. package/src/audit/checks/redirect-analysis.ts +0 -153
  76. package/src/audit/checks/redirect-chain.ts +0 -389
  77. package/src/audit/checks/resource-hints.ts +0 -420
  78. package/src/audit/checks/responsive-css.ts +0 -247
  79. package/src/audit/checks/responsive-images.ts +0 -396
  80. package/src/audit/checks/review-ecosystem.ts +0 -415
  81. package/src/audit/checks/robots-validation.ts +0 -373
  82. package/src/audit/checks/security-headers.ts +0 -188
  83. package/src/audit/checks/security.ts +0 -144
  84. package/src/audit/checks/serp-preview.ts +0 -251
  85. package/src/audit/checks/site-maturity.ts +0 -453
  86. package/src/audit/checks/social-meta.test.ts +0 -275
  87. package/src/audit/checks/social-meta.ts +0 -134
  88. package/src/audit/checks/soft-404.ts +0 -151
  89. package/src/audit/checks/structured-data.ts +0 -238
  90. package/src/audit/checks/tech-detection.ts +0 -496
  91. package/src/audit/checks/topical-clusters.ts +0 -435
  92. package/src/audit/checks/tracker-bloat.ts +0 -462
  93. package/src/audit/checks/tracking-verification.test.ts +0 -371
  94. package/src/audit/checks/tracking-verification.ts +0 -636
  95. package/src/audit/checks/url-safety.ts +0 -682
  96. package/src/audit/deno-entry.ts +0 -66
  97. package/src/audit/discovery/index.ts +0 -15
  98. package/src/audit/discovery/link-crawler.ts +0 -233
  99. package/src/audit/discovery/repo-routes.ts +0 -347
  100. package/src/audit/engine.ts +0 -627
  101. package/src/audit/fixes/index.ts +0 -209
  102. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  103. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  104. package/src/audit/index.ts +0 -74
  105. package/src/audit/runner.test.ts +0 -299
  106. package/src/audit/runner.ts +0 -130
  107. package/src/audit/types.ts +0 -1963
  108. package/src/content/featured-snippet.ts +0 -367
  109. package/src/content/generator.test.ts +0 -534
  110. package/src/content/generator.ts +0 -501
  111. package/src/content/headline.ts +0 -317
  112. package/src/content/index.ts +0 -62
  113. package/src/content/intent.ts +0 -258
  114. package/src/content/keyword-density.ts +0 -349
  115. package/src/content/readability.ts +0 -262
  116. package/src/executor.ts +0 -336
  117. package/src/fixer/framework-fixes.test.ts +0 -489
  118. package/src/fixer/framework-fixes.ts +0 -5287
  119. package/src/fixer/index.ts +0 -6
  120. package/src/fixer/schemas.ts +0 -971
  121. package/src/fixer.ts +0 -642
  122. package/src/frameworks/detector.test.ts +0 -248
  123. package/src/frameworks/detector.ts +0 -899
  124. package/src/frameworks/index.ts +0 -68
  125. package/src/frameworks/recipes/angular.yaml +0 -171
  126. package/src/frameworks/recipes/astro.yaml +0 -206
  127. package/src/frameworks/recipes/django.yaml +0 -180
  128. package/src/frameworks/recipes/laravel.yaml +0 -137
  129. package/src/frameworks/recipes/nextjs.yaml +0 -268
  130. package/src/frameworks/recipes/nuxt.yaml +0 -175
  131. package/src/frameworks/recipes/rails.yaml +0 -188
  132. package/src/frameworks/recipes/react.yaml +0 -202
  133. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  134. package/src/frameworks/recipes/vue.yaml +0 -137
  135. package/src/frameworks/recipes/wordpress.yaml +0 -209
  136. package/src/frameworks/suggestion-engine.ts +0 -357
  137. package/src/geo/geo-content.test.ts +0 -305
  138. package/src/geo/geo-content.ts +0 -266
  139. package/src/geo/geo-history.test.ts +0 -473
  140. package/src/geo/geo-history.ts +0 -433
  141. package/src/geo/geo-tracker.test.ts +0 -359
  142. package/src/geo/geo-tracker.ts +0 -411
  143. package/src/geo/index.ts +0 -11
  144. package/src/geo/llm-citation-checker.ts +0 -188
  145. package/src/git/commit-helper.test.ts +0 -261
  146. package/src/git/commit-helper.ts +0 -329
  147. package/src/git/index.ts +0 -12
  148. package/src/git/pr-helper.test.ts +0 -284
  149. package/src/git/pr-helper.ts +0 -307
  150. package/src/index.ts +0 -76
  151. package/src/keywords/ai-keyword-engine.ts +0 -1062
  152. package/src/keywords/ai-summarizer.ts +0 -387
  153. package/src/keywords/ci-mode.ts +0 -555
  154. package/src/keywords/engine.ts +0 -359
  155. package/src/keywords/index.ts +0 -151
  156. package/src/keywords/llm-judge.ts +0 -357
  157. package/src/keywords/nlp-analysis.ts +0 -706
  158. package/src/keywords/prioritizer.ts +0 -295
  159. package/src/keywords/site-crawler.ts +0 -342
  160. package/src/keywords/sources/autocomplete.ts +0 -139
  161. package/src/keywords/sources/competitive-search.ts +0 -450
  162. package/src/keywords/sources/competitor-analysis.ts +0 -374
  163. package/src/keywords/sources/dataforseo.ts +0 -206
  164. package/src/keywords/sources/free-sources.ts +0 -294
  165. package/src/keywords/sources/gsc.ts +0 -123
  166. package/src/keywords/topic-grouping.ts +0 -327
  167. package/src/keywords/types.ts +0 -144
  168. package/src/keywords/wizard.ts +0 -457
  169. package/src/loader.ts +0 -40
  170. package/src/ranking/index.ts +0 -5
  171. package/src/ranking/serp-client.ts +0 -348
  172. package/src/ranking/tracker.ts +0 -380
  173. package/src/ranking/types.ts +0 -123
  174. package/src/reports/index.ts +0 -7
  175. package/src/reports/report-generator.test.ts +0 -293
  176. package/src/reports/report-generator.ts +0 -713
  177. package/src/scheduler/alerts.test.ts +0 -458
  178. package/src/scheduler/alerts.ts +0 -328
  179. package/src/scheduler/index.ts +0 -8
  180. package/src/scheduler/scheduled-audit.test.ts +0 -377
  181. package/src/scheduler/scheduled-audit.ts +0 -149
  182. package/src/test/integration-test.ts +0 -325
  183. package/src/tools/analyzer.ts +0 -373
  184. package/src/tools/crawl.ts +0 -293
  185. package/src/tools/files.ts +0 -301
  186. package/src/tools/h1-fixer.ts +0 -249
  187. package/src/tools/index.ts +0 -67
  188. package/src/tracking/github-action.ts +0 -326
  189. package/src/tracking/google-analytics.ts +0 -265
  190. package/src/tracking/index.ts +0 -45
  191. package/src/tracking/report-generator.ts +0 -386
  192. package/src/tracking/search-console.ts +0 -335
  193. package/src/types.ts +0 -148
  194. package/src/utils/http.ts +0 -302
  195. package/src/wasm-adapter.ts +0 -297
  196. package/src/wasm-entry.ts +0 -14
  197. package/tsconfig.json +0 -17
  198. package/tsup.wasm.config.ts +0 -26
  199. 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
- }