@rankcli/agent-runtime 0.0.15 → 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 (202) hide show
  1. package/dist/index.d.mts +43 -393
  2. package/dist/index.d.ts +43 -393
  3. package/dist/index.js +306 -6526
  4. package/dist/index.mjs +202 -6412
  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/agent-experience.ts +0 -108
  28. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  29. package/src/audit/checks/ai-content-structure.ts +0 -325
  30. package/src/audit/checks/ai-readiness.ts +0 -406
  31. package/src/audit/checks/anchor-text.ts +0 -179
  32. package/src/audit/checks/answer-conciseness.ts +0 -322
  33. package/src/audit/checks/asset-minification.ts +0 -270
  34. package/src/audit/checks/bing-optimization.ts +0 -206
  35. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  36. package/src/audit/checks/caching-headers.ts +0 -305
  37. package/src/audit/checks/canonical-advanced.ts +0 -150
  38. package/src/audit/checks/canonical-domain.ts +0 -196
  39. package/src/audit/checks/citation-quality.ts +0 -358
  40. package/src/audit/checks/client-rendering.ts +0 -542
  41. package/src/audit/checks/color-contrast.ts +0 -342
  42. package/src/audit/checks/content-freshness.ts +0 -170
  43. package/src/audit/checks/content-science.ts +0 -589
  44. package/src/audit/checks/conversion-elements.ts +0 -526
  45. package/src/audit/checks/crawlability.ts +0 -220
  46. package/src/audit/checks/directory-listing.ts +0 -172
  47. package/src/audit/checks/dom-analysis.ts +0 -191
  48. package/src/audit/checks/dom-size.ts +0 -246
  49. package/src/audit/checks/duplicate-content.ts +0 -194
  50. package/src/audit/checks/eeat-signals.ts +0 -990
  51. package/src/audit/checks/entity-seo.ts +0 -396
  52. package/src/audit/checks/featured-snippet.ts +0 -473
  53. package/src/audit/checks/freshness-signals.ts +0 -443
  54. package/src/audit/checks/funnel-intent.ts +0 -463
  55. package/src/audit/checks/hreflang.ts +0 -174
  56. package/src/audit/checks/html-compliance.ts +0 -302
  57. package/src/audit/checks/image-dimensions.ts +0 -167
  58. package/src/audit/checks/images.ts +0 -160
  59. package/src/audit/checks/indexnow.ts +0 -275
  60. package/src/audit/checks/interactive-tools.ts +0 -475
  61. package/src/audit/checks/internal-link-graph.ts +0 -436
  62. package/src/audit/checks/keyword-analysis.ts +0 -239
  63. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  64. package/src/audit/checks/keyword-placement.ts +0 -471
  65. package/src/audit/checks/links.ts +0 -273
  66. package/src/audit/checks/llms-txt.ts +0 -224
  67. package/src/audit/checks/local-seo.ts +0 -296
  68. package/src/audit/checks/mobile.ts +0 -167
  69. package/src/audit/checks/modern-images.ts +0 -226
  70. package/src/audit/checks/navboost-signals.ts +0 -395
  71. package/src/audit/checks/on-page.ts +0 -209
  72. package/src/audit/checks/page-resources.ts +0 -285
  73. package/src/audit/checks/pagination.ts +0 -180
  74. package/src/audit/checks/performance.ts +0 -153
  75. package/src/audit/checks/platform-presence.ts +0 -580
  76. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  77. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  78. package/src/audit/checks/redirect-analysis.ts +0 -153
  79. package/src/audit/checks/redirect-chain.ts +0 -389
  80. package/src/audit/checks/resource-hints.ts +0 -420
  81. package/src/audit/checks/responsive-css.ts +0 -247
  82. package/src/audit/checks/responsive-images.ts +0 -396
  83. package/src/audit/checks/review-ecosystem.ts +0 -415
  84. package/src/audit/checks/robots-validation.ts +0 -373
  85. package/src/audit/checks/security-headers.ts +0 -188
  86. package/src/audit/checks/security.ts +0 -144
  87. package/src/audit/checks/serp-preview.ts +0 -251
  88. package/src/audit/checks/site-maturity.ts +0 -453
  89. package/src/audit/checks/social-meta.test.ts +0 -275
  90. package/src/audit/checks/social-meta.ts +0 -134
  91. package/src/audit/checks/soft-404.ts +0 -151
  92. package/src/audit/checks/structured-data.ts +0 -238
  93. package/src/audit/checks/tech-detection.ts +0 -496
  94. package/src/audit/checks/topical-clusters.ts +0 -435
  95. package/src/audit/checks/tracker-bloat.ts +0 -462
  96. package/src/audit/checks/tracking-verification.test.ts +0 -371
  97. package/src/audit/checks/tracking-verification.ts +0 -636
  98. package/src/audit/checks/url-safety.ts +0 -682
  99. package/src/audit/deno-entry.ts +0 -66
  100. package/src/audit/discovery/index.ts +0 -15
  101. package/src/audit/discovery/link-crawler.ts +0 -233
  102. package/src/audit/discovery/repo-routes.ts +0 -347
  103. package/src/audit/engine.ts +0 -633
  104. package/src/audit/fixes/index.ts +0 -209
  105. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  106. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  107. package/src/audit/index.ts +0 -74
  108. package/src/audit/runner.test.ts +0 -299
  109. package/src/audit/runner.ts +0 -130
  110. package/src/audit/types.ts +0 -1987
  111. package/src/content/featured-snippet.ts +0 -367
  112. package/src/content/generator.test.ts +0 -534
  113. package/src/content/generator.ts +0 -501
  114. package/src/content/headline.ts +0 -317
  115. package/src/content/index.ts +0 -62
  116. package/src/content/intent.ts +0 -258
  117. package/src/content/keyword-density.ts +0 -349
  118. package/src/content/readability.ts +0 -262
  119. package/src/executor.ts +0 -336
  120. package/src/fixer/framework-fixes.test.ts +0 -489
  121. package/src/fixer/framework-fixes.ts +0 -5287
  122. package/src/fixer/index.ts +0 -6
  123. package/src/fixer/schemas.ts +0 -971
  124. package/src/fixer.ts +0 -642
  125. package/src/frameworks/detector.test.ts +0 -248
  126. package/src/frameworks/detector.ts +0 -899
  127. package/src/frameworks/index.ts +0 -68
  128. package/src/frameworks/recipes/angular.yaml +0 -171
  129. package/src/frameworks/recipes/astro.yaml +0 -206
  130. package/src/frameworks/recipes/django.yaml +0 -180
  131. package/src/frameworks/recipes/laravel.yaml +0 -137
  132. package/src/frameworks/recipes/nextjs.yaml +0 -268
  133. package/src/frameworks/recipes/nuxt.yaml +0 -175
  134. package/src/frameworks/recipes/rails.yaml +0 -188
  135. package/src/frameworks/recipes/react.yaml +0 -202
  136. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  137. package/src/frameworks/recipes/vue.yaml +0 -137
  138. package/src/frameworks/recipes/wordpress.yaml +0 -209
  139. package/src/frameworks/suggestion-engine.ts +0 -357
  140. package/src/geo/geo-content.test.ts +0 -305
  141. package/src/geo/geo-content.ts +0 -266
  142. package/src/geo/geo-history.test.ts +0 -473
  143. package/src/geo/geo-history.ts +0 -433
  144. package/src/geo/geo-tracker.test.ts +0 -359
  145. package/src/geo/geo-tracker.ts +0 -411
  146. package/src/geo/index.ts +0 -11
  147. package/src/geo/llm-citation-checker.ts +0 -188
  148. package/src/git/commit-helper.test.ts +0 -261
  149. package/src/git/commit-helper.ts +0 -329
  150. package/src/git/index.ts +0 -12
  151. package/src/git/pr-helper.test.ts +0 -284
  152. package/src/git/pr-helper.ts +0 -307
  153. package/src/index.ts +0 -76
  154. package/src/keywords/ai-keyword-engine.ts +0 -1062
  155. package/src/keywords/ai-summarizer.ts +0 -387
  156. package/src/keywords/ci-mode.ts +0 -555
  157. package/src/keywords/engine.ts +0 -359
  158. package/src/keywords/index.ts +0 -151
  159. package/src/keywords/llm-judge.ts +0 -357
  160. package/src/keywords/nlp-analysis.ts +0 -706
  161. package/src/keywords/prioritizer.ts +0 -295
  162. package/src/keywords/site-crawler.ts +0 -342
  163. package/src/keywords/sources/autocomplete.ts +0 -139
  164. package/src/keywords/sources/competitive-search.ts +0 -450
  165. package/src/keywords/sources/competitor-analysis.ts +0 -374
  166. package/src/keywords/sources/dataforseo.ts +0 -206
  167. package/src/keywords/sources/free-sources.ts +0 -294
  168. package/src/keywords/sources/gsc.ts +0 -123
  169. package/src/keywords/topic-grouping.ts +0 -327
  170. package/src/keywords/types.ts +0 -144
  171. package/src/keywords/wizard.ts +0 -457
  172. package/src/loader.ts +0 -40
  173. package/src/ranking/index.ts +0 -5
  174. package/src/ranking/serp-client.ts +0 -348
  175. package/src/ranking/tracker.ts +0 -380
  176. package/src/ranking/types.ts +0 -123
  177. package/src/reports/index.ts +0 -7
  178. package/src/reports/report-generator.test.ts +0 -293
  179. package/src/reports/report-generator.ts +0 -713
  180. package/src/scheduler/alerts.test.ts +0 -458
  181. package/src/scheduler/alerts.ts +0 -328
  182. package/src/scheduler/index.ts +0 -8
  183. package/src/scheduler/scheduled-audit.test.ts +0 -377
  184. package/src/scheduler/scheduled-audit.ts +0 -149
  185. package/src/test/integration-test.ts +0 -325
  186. package/src/tools/analyzer.ts +0 -373
  187. package/src/tools/crawl.ts +0 -293
  188. package/src/tools/files.ts +0 -301
  189. package/src/tools/h1-fixer.ts +0 -249
  190. package/src/tools/index.ts +0 -67
  191. package/src/tracking/github-action.ts +0 -326
  192. package/src/tracking/google-analytics.ts +0 -265
  193. package/src/tracking/index.ts +0 -45
  194. package/src/tracking/report-generator.ts +0 -386
  195. package/src/tracking/search-console.ts +0 -335
  196. package/src/types.ts +0 -148
  197. package/src/utils/http.ts +0 -302
  198. package/src/wasm-adapter.ts +0 -297
  199. package/src/wasm-entry.ts +0 -14
  200. package/tsconfig.json +0 -17
  201. package/tsup.wasm.config.ts +0 -26
  202. package/vitest.config.ts +0 -15
@@ -1,275 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { analyzeSocialMeta } from './social-meta.js';
3
-
4
- describe('analyzeSocialMeta', () => {
5
- const testUrl = 'https://example.com';
6
-
7
- describe('Open Graph analysis', () => {
8
- it('detects all Open Graph tags when present', () => {
9
- const html = `
10
- <html>
11
- <head>
12
- <meta property="og:title" content="Test Title" />
13
- <meta property="og:description" content="Test Description" />
14
- <meta property="og:image" content="https://example.com/og.png" />
15
- <meta property="og:url" content="https://example.com" />
16
- <meta property="og:type" content="website" />
17
- <meta property="og:site_name" content="Test Site" />
18
- </head>
19
- </html>
20
- `;
21
-
22
- const { data, issues } = analyzeSocialMeta(html, testUrl);
23
-
24
- expect(data.openGraph.title).toBe('Test Title');
25
- expect(data.openGraph.description).toBe('Test Description');
26
- expect(data.openGraph.image).toBe('https://example.com/og.png');
27
- expect(data.openGraph.url).toBe('https://example.com');
28
- expect(data.openGraph.type).toBe('website');
29
- expect(data.openGraph.siteName).toBe('Test Site');
30
-
31
- // Should not have OG-related issues
32
- const ogIssues = issues.filter((i) => i.code.startsWith('OG_'));
33
- expect(ogIssues).toHaveLength(0);
34
- });
35
-
36
- it('reports missing og:title', () => {
37
- const html = `<html><head></head></html>`;
38
-
39
- const { issues } = analyzeSocialMeta(html, testUrl);
40
-
41
- const issue = issues.find((i) => i.code === 'OG_TITLE_MISSING');
42
- expect(issue).toBeDefined();
43
- expect(issue?.severity).toBe('warning');
44
- expect(issue?.affectedUrls).toContain(testUrl);
45
- });
46
-
47
- it('reports missing og:description', () => {
48
- const html = `<html><head></head></html>`;
49
-
50
- const { issues } = analyzeSocialMeta(html, testUrl);
51
-
52
- const issue = issues.find((i) => i.code === 'OG_DESCRIPTION_MISSING');
53
- expect(issue).toBeDefined();
54
- });
55
-
56
- it('reports missing og:image', () => {
57
- const html = `<html><head></head></html>`;
58
-
59
- const { issues } = analyzeSocialMeta(html, testUrl);
60
-
61
- const issue = issues.find((i) => i.code === 'OG_IMAGE_MISSING');
62
- expect(issue).toBeDefined();
63
- });
64
-
65
- it('reports missing og:url', () => {
66
- const html = `<html><head></head></html>`;
67
-
68
- const { issues } = analyzeSocialMeta(html, testUrl);
69
-
70
- const issue = issues.find((i) => i.code === 'OG_URL_MISSING');
71
- expect(issue).toBeDefined();
72
- });
73
-
74
- it('reports missing og:type', () => {
75
- const html = `<html><head></head></html>`;
76
-
77
- const { issues } = analyzeSocialMeta(html, testUrl);
78
-
79
- const issue = issues.find((i) => i.code === 'OG_TYPE_MISSING');
80
- expect(issue).toBeDefined();
81
- });
82
- });
83
-
84
- describe('Twitter Card analysis', () => {
85
- it('detects all Twitter Card tags when present', () => {
86
- const html = `
87
- <html>
88
- <head>
89
- <meta name="twitter:card" content="summary_large_image" />
90
- <meta name="twitter:title" content="Twitter Title" />
91
- <meta name="twitter:description" content="Twitter Description" />
92
- <meta name="twitter:image" content="https://example.com/twitter.png" />
93
- <meta name="twitter:site" content="@example" />
94
- <meta name="twitter:creator" content="@author" />
95
- </head>
96
- </html>
97
- `;
98
-
99
- const { data, issues } = analyzeSocialMeta(html, testUrl);
100
-
101
- expect(data.twitter.card).toBe('summary_large_image');
102
- expect(data.twitter.title).toBe('Twitter Title');
103
- expect(data.twitter.description).toBe('Twitter Description');
104
- expect(data.twitter.image).toBe('https://example.com/twitter.png');
105
- expect(data.twitter.site).toBe('@example');
106
- expect(data.twitter.creator).toBe('@author');
107
-
108
- // Should not have Twitter-related issues
109
- const twitterIssues = issues.filter((i) => i.code.startsWith('TWITTER_'));
110
- expect(twitterIssues).toHaveLength(0);
111
- });
112
-
113
- it('reports missing twitter:card', () => {
114
- const html = `<html><head></head></html>`;
115
-
116
- const { issues } = analyzeSocialMeta(html, testUrl);
117
-
118
- const issue = issues.find((i) => i.code === 'TWITTER_CARD_MISSING');
119
- expect(issue).toBeDefined();
120
- // Twitter card is a notice since it's less critical than OG tags
121
- expect(issue?.severity).toBe('notice');
122
- });
123
-
124
- it('does not report missing twitter:image if og:image exists', () => {
125
- const html = `
126
- <html>
127
- <head>
128
- <meta property="og:image" content="https://example.com/og.png" />
129
- </head>
130
- </html>
131
- `;
132
-
133
- const { issues } = analyzeSocialMeta(html, testUrl);
134
-
135
- const issue = issues.find((i) => i.code === 'TWITTER_IMAGE_MISSING');
136
- expect(issue).toBeUndefined();
137
- });
138
-
139
- it('reports missing twitter:image if no og:image', () => {
140
- const html = `<html><head></head></html>`;
141
-
142
- const { issues } = analyzeSocialMeta(html, testUrl);
143
-
144
- const issue = issues.find((i) => i.code === 'TWITTER_IMAGE_MISSING');
145
- expect(issue).toBeDefined();
146
- });
147
- });
148
-
149
- describe('Favicon analysis', () => {
150
- it('detects standard favicon', () => {
151
- const html = `
152
- <html>
153
- <head>
154
- <link rel="icon" href="/favicon.ico" />
155
- </head>
156
- </html>
157
- `;
158
-
159
- const { data, issues } = analyzeSocialMeta(html, testUrl);
160
-
161
- expect(data.hasFavicon).toBe(true);
162
- const issue = issues.find((i) => i.code === 'FAVICON_MISSING');
163
- expect(issue).toBeUndefined();
164
- });
165
-
166
- it('detects shortcut icon', () => {
167
- const html = `
168
- <html>
169
- <head>
170
- <link rel="shortcut icon" href="/favicon.ico" />
171
- </head>
172
- </html>
173
- `;
174
-
175
- const { data } = analyzeSocialMeta(html, testUrl);
176
- expect(data.hasFavicon).toBe(true);
177
- });
178
-
179
- it('detects apple-touch-icon', () => {
180
- const html = `
181
- <html>
182
- <head>
183
- <link rel="apple-touch-icon" href="/apple-icon.png" />
184
- </head>
185
- </html>
186
- `;
187
-
188
- const { data } = analyzeSocialMeta(html, testUrl);
189
- expect(data.hasFavicon).toBe(true);
190
- });
191
-
192
- it('reports missing favicon', () => {
193
- const html = `<html><head></head></html>`;
194
-
195
- const { data, issues } = analyzeSocialMeta(html, testUrl);
196
-
197
- expect(data.hasFavicon).toBe(false);
198
- const issue = issues.find((i) => i.code === 'FAVICON_MISSING');
199
- expect(issue).toBeDefined();
200
- });
201
- });
202
-
203
- describe('Lang attribute analysis', () => {
204
- it('detects lang attribute', () => {
205
- const html = `<html lang="en"><head></head></html>`;
206
-
207
- const { data, issues } = analyzeSocialMeta(html, testUrl);
208
-
209
- expect(data.langAttribute).toBe('en');
210
- const issue = issues.find((i) => i.code === 'LANG_ATTR_MISSING');
211
- expect(issue).toBeUndefined();
212
- });
213
-
214
- it('reports missing lang attribute', () => {
215
- const html = `<html><head></head></html>`;
216
-
217
- const { data, issues } = analyzeSocialMeta(html, testUrl);
218
-
219
- expect(data.langAttribute).toBeUndefined();
220
- const issue = issues.find((i) => i.code === 'LANG_ATTR_MISSING');
221
- expect(issue).toBeDefined();
222
- });
223
-
224
- it('handles different lang formats', () => {
225
- const html = `<html lang="en-US"><head></head></html>`;
226
-
227
- const { data } = analyzeSocialMeta(html, testUrl);
228
- expect(data.langAttribute).toBe('en-US');
229
- });
230
- });
231
-
232
- describe('Complete HTML analysis', () => {
233
- it('analyzes fully compliant HTML', () => {
234
- const html = `
235
- <!DOCTYPE html>
236
- <html lang="en">
237
- <head>
238
- <meta property="og:title" content="Test Page" />
239
- <meta property="og:description" content="A description" />
240
- <meta property="og:image" content="https://example.com/og.png" />
241
- <meta property="og:url" content="https://example.com" />
242
- <meta property="og:type" content="website" />
243
- <meta name="twitter:card" content="summary_large_image" />
244
- <meta name="twitter:image" content="https://example.com/twitter.png" />
245
- <link rel="icon" href="/favicon.ico" />
246
- </head>
247
- <body></body>
248
- </html>
249
- `;
250
-
251
- const { issues } = analyzeSocialMeta(html, testUrl);
252
-
253
- // Should have no issues for a fully compliant page
254
- expect(issues).toHaveLength(0);
255
- });
256
-
257
- it('analyzes completely non-compliant HTML', () => {
258
- const html = `<html><head></head><body></body></html>`;
259
-
260
- const { issues } = analyzeSocialMeta(html, testUrl);
261
-
262
- // Should have multiple issues
263
- expect(issues.length).toBeGreaterThan(5);
264
-
265
- // Check for specific issues
266
- const issueCodes = issues.map((i) => i.code);
267
- expect(issueCodes).toContain('OG_TITLE_MISSING');
268
- expect(issueCodes).toContain('OG_DESCRIPTION_MISSING');
269
- expect(issueCodes).toContain('OG_IMAGE_MISSING');
270
- expect(issueCodes).toContain('TWITTER_CARD_MISSING');
271
- expect(issueCodes).toContain('FAVICON_MISSING');
272
- expect(issueCodes).toContain('LANG_ATTR_MISSING');
273
- });
274
- });
275
- });
@@ -1,134 +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 SocialMetaData {
6
- openGraph: {
7
- title?: string;
8
- description?: string;
9
- image?: string;
10
- url?: string;
11
- type?: string;
12
- siteName?: string;
13
- };
14
- twitter: {
15
- card?: string;
16
- title?: string;
17
- description?: string;
18
- image?: string;
19
- site?: string;
20
- creator?: string;
21
- };
22
- hasFavicon: boolean;
23
- langAttribute?: string;
24
- }
25
-
26
- export function analyzeSocialMeta(html: string, url: string): { issues: AuditIssue[]; data: SocialMetaData } {
27
- const issues: AuditIssue[] = [];
28
- const $ = cheerio.load(html);
29
-
30
- // Extract Open Graph data
31
- const openGraph = {
32
- title: $('meta[property="og:title"]').attr('content'),
33
- description: $('meta[property="og:description"]').attr('content'),
34
- image: $('meta[property="og:image"]').attr('content'),
35
- url: $('meta[property="og:url"]').attr('content'),
36
- type: $('meta[property="og:type"]').attr('content'),
37
- siteName: $('meta[property="og:site_name"]').attr('content'),
38
- };
39
-
40
- // Extract Twitter Card data
41
- const twitter = {
42
- card: $('meta[name="twitter:card"]').attr('content'),
43
- title: $('meta[name="twitter:title"]').attr('content'),
44
- description: $('meta[name="twitter:description"]').attr('content'),
45
- image: $('meta[name="twitter:image"]').attr('content'),
46
- site: $('meta[name="twitter:site"]').attr('content'),
47
- creator: $('meta[name="twitter:creator"]').attr('content'),
48
- };
49
-
50
- // Check favicon
51
- const hasFavicon = $('link[rel="icon"]').length > 0 ||
52
- $('link[rel="shortcut icon"]').length > 0 ||
53
- $('link[rel="apple-touch-icon"]').length > 0;
54
-
55
- // Check lang attribute
56
- const langAttribute = $('html').attr('lang');
57
-
58
- const data: SocialMetaData = {
59
- openGraph,
60
- twitter,
61
- hasFavicon,
62
- langAttribute,
63
- };
64
-
65
- // ==================== Open Graph Checks ====================
66
- if (!openGraph.title) {
67
- issues.push({
68
- ...ISSUE_DEFINITIONS.OG_TITLE_MISSING,
69
- affectedUrls: [url],
70
- });
71
- }
72
-
73
- if (!openGraph.description) {
74
- issues.push({
75
- ...ISSUE_DEFINITIONS.OG_DESCRIPTION_MISSING,
76
- affectedUrls: [url],
77
- });
78
- }
79
-
80
- if (!openGraph.image) {
81
- issues.push({
82
- ...ISSUE_DEFINITIONS.OG_IMAGE_MISSING,
83
- affectedUrls: [url],
84
- });
85
- }
86
-
87
- if (!openGraph.url) {
88
- issues.push({
89
- ...ISSUE_DEFINITIONS.OG_URL_MISSING,
90
- affectedUrls: [url],
91
- });
92
- }
93
-
94
- if (!openGraph.type) {
95
- issues.push({
96
- ...ISSUE_DEFINITIONS.OG_TYPE_MISSING,
97
- affectedUrls: [url],
98
- });
99
- }
100
-
101
- // ==================== Twitter Card Checks ====================
102
- if (!twitter.card) {
103
- issues.push({
104
- ...ISSUE_DEFINITIONS.TWITTER_CARD_MISSING,
105
- affectedUrls: [url],
106
- });
107
- }
108
-
109
- if (!twitter.image && !openGraph.image) {
110
- // Only flag if no OG image either (Twitter falls back to OG)
111
- issues.push({
112
- ...ISSUE_DEFINITIONS.TWITTER_IMAGE_MISSING,
113
- affectedUrls: [url],
114
- });
115
- }
116
-
117
- // ==================== Favicon Check ====================
118
- if (!hasFavicon) {
119
- issues.push({
120
- ...ISSUE_DEFINITIONS.FAVICON_MISSING,
121
- affectedUrls: [url],
122
- });
123
- }
124
-
125
- // ==================== Lang Attribute Check ====================
126
- if (!langAttribute) {
127
- issues.push({
128
- ...ISSUE_DEFINITIONS.LANG_ATTR_MISSING,
129
- affectedUrls: [url],
130
- });
131
- }
132
-
133
- return { issues, data };
134
- }
@@ -1,151 +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 Soft404Data {
6
- isSoft404: boolean;
7
- confidence: number;
8
- signals: string[];
9
- }
10
-
11
- // Common error page phrases
12
- const ERROR_PHRASES = [
13
- 'page not found',
14
- '404',
15
- 'not found',
16
- 'page doesn\'t exist',
17
- 'page does not exist',
18
- 'no longer available',
19
- 'has been removed',
20
- 'has been deleted',
21
- 'couldn\'t find',
22
- 'could not find',
23
- 'doesn\'t exist',
24
- 'does not exist',
25
- 'no results found',
26
- 'nothing found',
27
- 'sorry, we couldn\'t find',
28
- 'oops',
29
- 'error occurred',
30
- 'something went wrong',
31
- 'page you requested',
32
- 'page you were looking for',
33
- 'this page isn\'t available',
34
- 'this page is not available',
35
- 'we can\'t find',
36
- 'we cannot find',
37
- ];
38
-
39
- // Common error page title patterns
40
- const ERROR_TITLE_PATTERNS = [
41
- /404/i,
42
- /not found/i,
43
- /page.*not.*found/i,
44
- /error/i,
45
- /oops/i,
46
- ];
47
-
48
- export function detectSoft404(
49
- html: string,
50
- url: string,
51
- statusCode: number = 200
52
- ): { issues: AuditIssue[]; data: Soft404Data } {
53
- const issues: AuditIssue[] = [];
54
- const $ = cheerio.load(html);
55
- const signals: string[] = [];
56
- let score = 0;
57
-
58
- // Only check pages that return 200
59
- if (statusCode !== 200) {
60
- return {
61
- issues,
62
- data: { isSoft404: false, confidence: 0, signals: [] },
63
- };
64
- }
65
-
66
- const title = $('title').text().toLowerCase();
67
- const bodyText = $('body').text().toLowerCase().replace(/\s+/g, ' ');
68
- const h1 = $('h1').first().text().toLowerCase();
69
-
70
- // Check title for error patterns
71
- for (const pattern of ERROR_TITLE_PATTERNS) {
72
- if (pattern.test(title)) {
73
- score += 30;
74
- signals.push(`Title matches error pattern: "${title.substring(0, 50)}"`);
75
- break;
76
- }
77
- }
78
-
79
- // Check H1 for error patterns
80
- for (const pattern of ERROR_TITLE_PATTERNS) {
81
- if (pattern.test(h1)) {
82
- score += 25;
83
- signals.push(`H1 matches error pattern: "${h1.substring(0, 50)}"`);
84
- break;
85
- }
86
- }
87
-
88
- // Check body text for error phrases
89
- let errorPhraseCount = 0;
90
- for (const phrase of ERROR_PHRASES) {
91
- if (bodyText.includes(phrase)) {
92
- errorPhraseCount++;
93
- if (errorPhraseCount <= 3) {
94
- signals.push(`Body contains error phrase: "${phrase}"`);
95
- }
96
- }
97
- }
98
- score += Math.min(errorPhraseCount * 10, 30);
99
-
100
- // Check for very thin content (common in error pages)
101
- const wordCount = bodyText.split(/\s+/).filter(w => w.length > 0).length;
102
- if (wordCount < 100) {
103
- score += 15;
104
- signals.push(`Very thin content: ${wordCount} words`);
105
- }
106
-
107
- // Check for search form on error-like pages (common pattern)
108
- const hasSearchForm = $('form[action*="search"]').length > 0 ||
109
- $('input[type="search"]').length > 0 ||
110
- $('input[name="q"]').length > 0 ||
111
- $('input[name="search"]').length > 0;
112
-
113
- // Search form + error signals = higher soft 404 confidence
114
- if (hasSearchForm && score > 20) {
115
- score += 10;
116
- signals.push('Page has search form (common on 404 pages)');
117
- }
118
-
119
- // Check for common 404 page CSS classes
120
- const errorClasses = ['error', '404', 'not-found', 'notfound', 'page-error'];
121
- for (const cls of errorClasses) {
122
- if ($(`[class*="${cls}"]`).length > 0) {
123
- score += 10;
124
- signals.push(`Found error-related CSS class containing "${cls}"`);
125
- break;
126
- }
127
- }
128
-
129
- // Calculate confidence (0-100)
130
- const confidence = Math.min(score, 100);
131
- const isSoft404 = confidence >= 50;
132
-
133
- const data: Soft404Data = {
134
- isSoft404,
135
- confidence,
136
- signals,
137
- };
138
-
139
- if (isSoft404) {
140
- issues.push({
141
- ...ISSUE_DEFINITIONS.SOFT_404,
142
- affectedUrls: [url],
143
- details: {
144
- confidence: `${confidence}%`,
145
- signals: signals.slice(0, 5),
146
- },
147
- });
148
- }
149
-
150
- return { issues, data };
151
- }