@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,251 +0,0 @@
1
- // SERP Preview and Pixel-based Meta Analysis
2
- // Calculates pixel widths for title and description for accurate SERP display prediction
3
-
4
- import * as cheerio from 'cheerio';
5
- import type { AuditIssue } from '../types.js';
6
- import { ISSUE_DEFINITIONS } from '../types.js';
7
-
8
- // Google's approximate character widths in pixels (based on their font)
9
- // This is a simplified approximation - real pixel widths vary by character
10
- const CHAR_WIDTHS: Record<string, number> = {
11
- // Lowercase letters
12
- a: 9, b: 9, c: 8, d: 9, e: 9, f: 5, g: 9, h: 9, i: 4, j: 4,
13
- k: 8, l: 4, m: 14, n: 9, o: 9, p: 9, q: 9, r: 6, s: 8, t: 5,
14
- u: 9, v: 8, w: 12, x: 8, y: 8, z: 7,
15
- // Uppercase letters
16
- A: 11, B: 10, C: 10, D: 11, E: 9, F: 9, G: 11, H: 11, I: 4, J: 8,
17
- K: 10, L: 8, M: 13, N: 11, O: 12, P: 10, Q: 12, R: 10, S: 10, T: 9,
18
- U: 11, V: 10, W: 14, X: 10, Y: 10, Z: 9,
19
- // Numbers
20
- '0': 9, '1': 9, '2': 9, '3': 9, '4': 9, '5': 9, '6': 9, '7': 9, '8': 9, '9': 9,
21
- // Common punctuation and spaces
22
- ' ': 4, '.': 4, ',': 4, '!': 4, '?': 8, '-': 5, '_': 8, ':': 4, ';': 4,
23
- "'": 3, '"': 6, '(': 5, ')': 5, '[': 5, ']': 5, '/': 5, '|': 4, '&': 10,
24
- '@': 14, '#': 9, '$': 9, '%': 12, '^': 7, '*': 6, '+': 9, '=': 9,
25
- };
26
-
27
- // Default width for unknown characters
28
- const DEFAULT_CHAR_WIDTH = 9;
29
-
30
- // SERP pixel limits
31
- const TITLE_MAX_PIXELS = 580; // Google's title limit
32
- const DESCRIPTION_MAX_PIXELS_DESKTOP = 920; // Desktop description limit
33
- const DESCRIPTION_MAX_PIXELS_MOBILE = 680; // Mobile description limit
34
-
35
- export interface SERPPreviewData {
36
- title: {
37
- text: string;
38
- charLength: number;
39
- pixelWidth: number;
40
- truncated: boolean;
41
- displayText: string;
42
- };
43
- description: {
44
- text: string;
45
- charLength: number;
46
- pixelWidthDesktop: number;
47
- pixelWidthMobile: number;
48
- truncatedDesktop: boolean;
49
- truncatedMobile: boolean;
50
- displayTextDesktop: string;
51
- displayTextMobile: string;
52
- };
53
- url: {
54
- display: string;
55
- breadcrumbs: string[];
56
- };
57
- preview: {
58
- desktop: string;
59
- mobile: string;
60
- };
61
- }
62
-
63
- /**
64
- * Calculate pixel width of a string
65
- */
66
- function calculatePixelWidth(text: string): number {
67
- let width = 0;
68
- for (const char of text) {
69
- width += CHAR_WIDTHS[char] ?? DEFAULT_CHAR_WIDTH;
70
- }
71
- return width;
72
- }
73
-
74
- /**
75
- * Truncate text to fit within pixel limit
76
- */
77
- function truncateToPixels(text: string, maxPixels: number): { text: string; truncated: boolean } {
78
- let width = 0;
79
- let truncated = false;
80
-
81
- for (let i = 0; i < text.length; i++) {
82
- const charWidth = CHAR_WIDTHS[text[i]] ?? DEFAULT_CHAR_WIDTH;
83
- if (width + charWidth > maxPixels - 20) {
84
- // Leave room for "..."
85
- truncated = true;
86
- return { text: text.substring(0, i) + '...', truncated };
87
- }
88
- width += charWidth;
89
- }
90
-
91
- return { text, truncated };
92
- }
93
-
94
- /**
95
- * Format URL for SERP display
96
- */
97
- function formatSERPUrl(url: string): { display: string; breadcrumbs: string[] } {
98
- try {
99
- const parsed = new URL(url);
100
- const domain = parsed.hostname.replace(/^www\./, '');
101
- const pathParts = parsed.pathname.split('/').filter(Boolean);
102
-
103
- // Create breadcrumb-style path
104
- const breadcrumbs = [domain, ...pathParts];
105
-
106
- // SERP display format
107
- const display = breadcrumbs.join(' › ');
108
-
109
- return { display, breadcrumbs };
110
- } catch {
111
- return { display: url, breadcrumbs: [url] };
112
- }
113
- }
114
-
115
- /**
116
- * Analyze SERP preview and generate pixel-based issues
117
- */
118
- export function analyzeSERPPreview(html: string, url: string): { issues: AuditIssue[]; data: SERPPreviewData } {
119
- const issues: AuditIssue[] = [];
120
- const $ = cheerio.load(html);
121
-
122
- // Extract title
123
- const rawTitle = $('title').text().trim() || '';
124
- const titlePixels = calculatePixelWidth(rawTitle);
125
- const titleTruncated = truncateToPixels(rawTitle, TITLE_MAX_PIXELS);
126
-
127
- // Extract meta description
128
- const rawDescription =
129
- $('meta[name="description"]').attr('content')?.trim() ||
130
- $('meta[property="og:description"]').attr('content')?.trim() ||
131
- '';
132
- const descPixelsDesktop = calculatePixelWidth(rawDescription);
133
- const descPixelsMobile = calculatePixelWidth(rawDescription);
134
- const descTruncatedDesktop = truncateToPixels(rawDescription, DESCRIPTION_MAX_PIXELS_DESKTOP);
135
- const descTruncatedMobile = truncateToPixels(rawDescription, DESCRIPTION_MAX_PIXELS_MOBILE);
136
-
137
- // Format URL
138
- const urlData = formatSERPUrl(url);
139
-
140
- // Generate issues
141
- if (titleTruncated.truncated) {
142
- issues.push({
143
- ...ISSUE_DEFINITIONS.TITLE_TRUNCATED_SERP,
144
- affectedUrls: [url],
145
- details: {
146
- pixelWidth: titlePixels,
147
- maxPixels: TITLE_MAX_PIXELS,
148
- charLength: rawTitle.length,
149
- displayPreview: titleTruncated.text,
150
- },
151
- });
152
- }
153
-
154
- if (descTruncatedDesktop.truncated) {
155
- issues.push({
156
- ...ISSUE_DEFINITIONS.META_DESC_TRUNCATED_SERP,
157
- affectedUrls: [url],
158
- details: {
159
- pixelWidth: descPixelsDesktop,
160
- maxPixels: DESCRIPTION_MAX_PIXELS_DESKTOP,
161
- charLength: rawDescription.length,
162
- displayPreview: descTruncatedDesktop.text,
163
- },
164
- });
165
- }
166
-
167
- // Build preview data
168
- const data: SERPPreviewData = {
169
- title: {
170
- text: rawTitle,
171
- charLength: rawTitle.length,
172
- pixelWidth: titlePixels,
173
- truncated: titleTruncated.truncated,
174
- displayText: titleTruncated.text,
175
- },
176
- description: {
177
- text: rawDescription,
178
- charLength: rawDescription.length,
179
- pixelWidthDesktop: descPixelsDesktop,
180
- pixelWidthMobile: descPixelsMobile,
181
- truncatedDesktop: descTruncatedDesktop.truncated,
182
- truncatedMobile: descTruncatedMobile.truncated,
183
- displayTextDesktop: descTruncatedDesktop.text,
184
- displayTextMobile: descTruncatedMobile.text,
185
- },
186
- url: urlData,
187
- preview: {
188
- desktop: generateDesktopPreview(titleTruncated.text, descTruncatedDesktop.text, urlData.display),
189
- mobile: generateMobilePreview(titleTruncated.text, descTruncatedMobile.text, urlData.display),
190
- },
191
- };
192
-
193
- return { issues, data };
194
- }
195
-
196
- /**
197
- * Generate ASCII art SERP preview for desktop
198
- */
199
- function generateDesktopPreview(title: string, description: string, url: string): string {
200
- const maxWidth = 60;
201
- const titleLine = title.length > maxWidth ? title.substring(0, maxWidth - 3) + '...' : title;
202
- const urlLine = url.length > maxWidth ? url.substring(0, maxWidth - 3) + '...' : url;
203
- const descLines = wrapText(description, maxWidth);
204
-
205
- return [
206
- '┌' + '─'.repeat(maxWidth + 2) + '┐',
207
- '│ ' + titleLine.padEnd(maxWidth) + ' │',
208
- '│ ' + urlLine.padEnd(maxWidth) + ' │',
209
- ...descLines.map((line) => '│ ' + line.padEnd(maxWidth) + ' │'),
210
- '└' + '─'.repeat(maxWidth + 2) + '┘',
211
- ].join('\n');
212
- }
213
-
214
- /**
215
- * Generate ASCII art SERP preview for mobile
216
- */
217
- function generateMobilePreview(title: string, description: string, url: string): string {
218
- const maxWidth = 40;
219
- const titleLine = title.length > maxWidth ? title.substring(0, maxWidth - 3) + '...' : title;
220
- const urlLine = url.length > maxWidth ? url.substring(0, maxWidth - 3) + '...' : url;
221
- const descLines = wrapText(description, maxWidth);
222
-
223
- return [
224
- '┌' + '─'.repeat(maxWidth + 2) + '┐',
225
- '│ ' + titleLine.padEnd(maxWidth) + ' │',
226
- '│ ' + urlLine.padEnd(maxWidth) + ' │',
227
- ...descLines.slice(0, 2).map((line) => '│ ' + line.padEnd(maxWidth) + ' │'),
228
- '└' + '─'.repeat(maxWidth + 2) + '┘',
229
- ].join('\n');
230
- }
231
-
232
- /**
233
- * Wrap text to specified width
234
- */
235
- function wrapText(text: string, maxWidth: number): string[] {
236
- const words = text.split(' ');
237
- const lines: string[] = [];
238
- let currentLine = '';
239
-
240
- for (const word of words) {
241
- if ((currentLine + ' ' + word).trim().length <= maxWidth) {
242
- currentLine = (currentLine + ' ' + word).trim();
243
- } else {
244
- if (currentLine) lines.push(currentLine);
245
- currentLine = word;
246
- }
247
- }
248
- if (currentLine) lines.push(currentLine);
249
-
250
- return lines;
251
- }
@@ -1,453 +0,0 @@
1
- // Site Maturity Analysis - Different SEO Strategies for New vs Established Sites
2
- // Based on Nathan Gotch's advice: New sites should focus on authority building, not content proliferation
3
- // Reference: "How to do SEO when your website is new?"
4
-
5
- import { httpGet } from '../../utils/http.js';
6
- import * as cheerio from 'cheerio';
7
- import type { AuditIssue } from '../types.js';
8
-
9
- export type SiteMaturity = 'new' | 'growing' | 'established' | 'mature';
10
- export type SEOStrategy = 'authority-first' | 'content-expansion' | 'optimization' | 'maintenance';
11
-
12
- export interface SiteMaturityData {
13
- estimatedAge: {
14
- days: number | null;
15
- source: 'wayback' | 'whois' | 'ssl' | 'sitemap' | 'estimated';
16
- confidence: 'high' | 'medium' | 'low';
17
- };
18
- maturityLevel: SiteMaturity;
19
- authorityIndicators: {
20
- hasBacklinks: boolean;
21
- estimatedBacklinks: number;
22
- hasIndexedPages: boolean;
23
- indexedPagesEstimate: number;
24
- hasBrandMentions: boolean;
25
- sslAge: number | null; // days
26
- };
27
- contentMetrics: {
28
- pageCount: number;
29
- hasMultipleContentTypes: boolean;
30
- hasBlog: boolean;
31
- contentToAuthorityRatio: 'balanced' | 'content-heavy' | 'authority-heavy';
32
- };
33
- recommendedStrategy: SEOStrategy;
34
- strategicRecommendations: string[];
35
- }
36
-
37
- /**
38
- * Estimate domain age from SSL certificate issuance date
39
- */
40
- export async function getSSLCertificateAge(url: string): Promise<number | null> {
41
- // Dynamically import https module (Node.js only)
42
- let https: typeof import('https');
43
- try {
44
- https = await import('https');
45
- } catch {
46
- // Not available in Deno/browser
47
- return null;
48
- }
49
-
50
- return new Promise((resolve) => {
51
- try {
52
- const parsedUrl = new URL(url);
53
- const options = {
54
- host: parsedUrl.hostname,
55
- port: 443,
56
- method: 'GET',
57
- rejectUnauthorized: false, // Accept self-signed for checking
58
- };
59
-
60
- const req = https.request(options, (res) => {
61
- const cert = (res.socket as any).getPeerCertificate?.();
62
- if (cert && cert.valid_from) {
63
- const validFrom = new Date(cert.valid_from);
64
- const now = new Date();
65
- const ageDays = Math.floor((now.getTime() - validFrom.getTime()) / (1000 * 60 * 60 * 24));
66
- resolve(ageDays);
67
- } else {
68
- resolve(null);
69
- }
70
- });
71
-
72
- req.on('error', () => resolve(null));
73
- req.setTimeout(5000, () => {
74
- req.destroy();
75
- resolve(null);
76
- });
77
- req.end();
78
- } catch {
79
- resolve(null);
80
- }
81
- });
82
- }
83
-
84
- /**
85
- * Check Wayback Machine for earliest snapshot (approximate domain age)
86
- */
87
- export async function checkWaybackMachine(domain: string): Promise<{ firstSeen: Date | null; snapshots: number }> {
88
- try {
89
- // Wayback CDX API - get earliest snapshot
90
- const response = await httpGet<string>(
91
- `https://web.archive.org/cdx/search/cdx?url=${domain}&output=json&limit=1&from=1990`,
92
- {
93
- timeout: 10000,
94
- validateStatus: () => true,
95
- }
96
- );
97
-
98
- if (response.status === 200 && Array.isArray(response.data) && response.data.length > 1) {
99
- // First row is headers, second is earliest snapshot
100
- const timestamp = response.data[1]?.[1];
101
- if (timestamp) {
102
- // Wayback timestamp format: YYYYMMDDHHmmss
103
- const year = parseInt(timestamp.substring(0, 4));
104
- const month = parseInt(timestamp.substring(4, 6)) - 1;
105
- const day = parseInt(timestamp.substring(6, 8));
106
- return { firstSeen: new Date(year, month, day), snapshots: response.data.length - 1 };
107
- }
108
- }
109
-
110
- return { firstSeen: null, snapshots: 0 };
111
- } catch {
112
- return { firstSeen: null, snapshots: 0 };
113
- }
114
- }
115
-
116
- /**
117
- * Estimate number of indexed pages using site: query approximation
118
- * (Without Google API, we use heuristics from sitemap)
119
- */
120
- export async function estimateIndexedPages(url: string): Promise<number> {
121
- const origin = new URL(url).origin;
122
-
123
- try {
124
- // Check sitemap for page count
125
- const sitemapUrls = [
126
- `${origin}/sitemap.xml`,
127
- `${origin}/sitemap_index.xml`,
128
- `${origin}/sitemap-index.xml`,
129
- ];
130
-
131
- for (const sitemapUrl of sitemapUrls) {
132
- try {
133
- const response = await httpGet<string>(sitemapUrl, {
134
-
135
- timeout: 10000,
136
- validateStatus: () => true,
137
- });
138
-
139
- if (response.status === 200) {
140
- const $ = cheerio.load(response.data, { xmlMode: true });
141
-
142
- // Check if it's a sitemap index
143
- const sitemaps = $('sitemap').length;
144
- if (sitemaps > 0) {
145
- // Estimate: each sub-sitemap typically has ~1000 URLs
146
- return sitemaps * 500; // Conservative estimate
147
- }
148
-
149
- // Regular sitemap - count URLs
150
- const urls = $('url').length;
151
- if (urls > 0) {
152
- return urls;
153
- }
154
- }
155
- } catch {
156
- // Try next sitemap URL
157
- }
158
- }
159
-
160
- return 0; // Unable to estimate
161
- } catch {
162
- return 0;
163
- }
164
- }
165
-
166
- /**
167
- * Analyze HTML for site maturity signals
168
- */
169
- export function analyzeHTMLMaturitySignals(html: string, url: string): {
170
- hasBlog: boolean;
171
- hasMultipleContentTypes: boolean;
172
- hasEstablishedBrand: boolean;
173
- contentIndicators: string[];
174
- } {
175
- const $ = cheerio.load(html);
176
- const text = $('body').text().toLowerCase();
177
- const htmlLower = html.toLowerCase();
178
-
179
- // Blog detection
180
- const hasBlog =
181
- $('a[href*="/blog"]').length > 0 ||
182
- $('a[href*="/posts"]').length > 0 ||
183
- $('a[href*="/articles"]').length > 0 ||
184
- htmlLower.includes('/blog') ||
185
- $('[class*="blog"]').length > 0;
186
-
187
- // Multiple content types
188
- const contentIndicators: string[] = [];
189
- if (hasBlog) contentIndicators.push('blog');
190
- if ($('a[href*="/products"], [class*="product"]').length > 0) contentIndicators.push('products');
191
- if ($('a[href*="/services"], [class*="service"]').length > 0) contentIndicators.push('services');
192
- if ($('a[href*="/portfolio"], [class*="portfolio"]').length > 0) contentIndicators.push('portfolio');
193
- if ($('a[href*="/case-stud"], [class*="case"]').length > 0) contentIndicators.push('case-studies');
194
- if ($('a[href*="/testimonial"], [class*="testimonial"]').length > 0) contentIndicators.push('testimonials');
195
- if ($('a[href*="/resource"], [class*="resource"]').length > 0) contentIndicators.push('resources');
196
-
197
- const hasMultipleContentTypes = contentIndicators.length >= 3;
198
-
199
- // Established brand signals
200
- const hasEstablishedBrand =
201
- // Social proof
202
- ($('[class*="trust"], [class*="partner"], [class*="client"]').length > 0 ||
203
- // Press/media mentions
204
- text.includes('featured in') ||
205
- text.includes('as seen') ||
206
- text.includes('trusted by') ||
207
- // Awards/certifications
208
- text.includes('award') ||
209
- text.includes('certified') ||
210
- // Copyright with year range
211
- /©\s*\d{4}\s*-\s*\d{4}/.test(text) ||
212
- // Multiple social links
213
- $('a[href*="linkedin.com"], a[href*="twitter.com"], a[href*="facebook.com"]').length >= 2);
214
-
215
- return {
216
- hasBlog,
217
- hasMultipleContentTypes,
218
- hasEstablishedBrand,
219
- contentIndicators,
220
- };
221
- }
222
-
223
- /**
224
- * Determine recommended SEO strategy based on site maturity
225
- */
226
- export function determineStrategy(
227
- maturity: SiteMaturity,
228
- authorityIndicators: SiteMaturityData['authorityIndicators'],
229
- contentMetrics: SiteMaturityData['contentMetrics']
230
- ): { strategy: SEOStrategy; recommendations: string[] } {
231
- const recommendations: string[] = [];
232
-
233
- if (maturity === 'new') {
234
- // Nathan Gotch's advice: Focus on authority first
235
- recommendations.push(
236
- '🎯 PRIORITY: Build site authority before creating more content',
237
- '📝 Create ONE exceptional linkable asset (ultimate guide, original research, tool)',
238
- '🔗 Focus 80% of effort on link acquisition to your best page',
239
- '⏳ Wait until you have 10+ quality backlinks before content expansion',
240
- '❌ AVOID: Publishing lots of content that won\'t rank without authority'
241
- );
242
- return { strategy: 'authority-first', recommendations };
243
- }
244
-
245
- if (maturity === 'growing') {
246
- if (contentMetrics.contentToAuthorityRatio === 'content-heavy') {
247
- recommendations.push(
248
- '⚠️ Content-to-authority imbalance detected',
249
- '🔗 Pause content creation and focus on link building',
250
- '📊 Your content won\'t rank well without more domain authority',
251
- '🎯 Build 20-50 quality backlinks before adding more pages',
252
- '💡 Consider "Reverse Silo": Drive links to content assets, then internal link to money pages'
253
- );
254
- return { strategy: 'authority-first', recommendations };
255
- }
256
-
257
- recommendations.push(
258
- '🚀 You\'re in the growth phase - balance content and links',
259
- '📝 Create pillar content around 3-5 main topics',
260
- '🔗 Build 5-10 quality backlinks per month',
261
- '🏗️ Establish topic clusters with internal linking',
262
- '📈 Monitor rankings - optimize pages stuck on page 2'
263
- );
264
- return { strategy: 'content-expansion', recommendations };
265
- }
266
-
267
- if (maturity === 'established') {
268
- recommendations.push(
269
- '✅ Site has established authority - focus on optimization',
270
- '🔍 Audit existing content for improvement opportunities',
271
- '📊 Use data to find underperforming pages to refresh',
272
- '🎯 Target more competitive keywords',
273
- '💼 Consider merger technique: Acquire relevant expired domains',
274
- '🔗 Focus on earning links naturally through quality content'
275
- );
276
- return { strategy: 'optimization', recommendations };
277
- }
278
-
279
- // Mature sites
280
- recommendations.push(
281
- '👑 Mature site - maintain and defend rankings',
282
- '🔄 Regularly refresh top-performing content',
283
- '🛡️ Monitor for ranking drops and algorithm impacts',
284
- '📈 Expand into adjacent topics and markets',
285
- '🏆 Focus on brand building and E-E-A-T signals',
286
- '⚡ Optimize for Core Web Vitals and user experience'
287
- );
288
- return { strategy: 'maintenance', recommendations };
289
- }
290
-
291
- /**
292
- * Main function: Analyze site maturity and recommend strategy
293
- */
294
- export async function analyzeSiteMaturity(
295
- html: string,
296
- url: string
297
- ): Promise<{ issues: AuditIssue[]; data: SiteMaturityData }> {
298
- const issues: AuditIssue[] = [];
299
- const domain = new URL(url).hostname;
300
-
301
- // Gather maturity signals
302
- const [sslAge, wayback, indexedPages] = await Promise.all([
303
- getSSLCertificateAge(url),
304
- checkWaybackMachine(domain),
305
- estimateIndexedPages(url),
306
- ]);
307
-
308
- const htmlSignals = analyzeHTMLMaturitySignals(html, url);
309
-
310
- // Estimate age (prefer Wayback, fallback to SSL)
311
- let estimatedAgeDays: number | null = null;
312
- let ageSource: 'wayback' | 'ssl' | 'estimated' = 'estimated';
313
- let ageConfidence: 'high' | 'medium' | 'low' = 'low';
314
-
315
- if (wayback.firstSeen) {
316
- estimatedAgeDays = Math.floor((Date.now() - wayback.firstSeen.getTime()) / (1000 * 60 * 60 * 24));
317
- ageSource = 'wayback';
318
- ageConfidence = wayback.snapshots > 10 ? 'high' : 'medium';
319
- } else if (sslAge !== null && sslAge > 0) {
320
- estimatedAgeDays = sslAge;
321
- ageSource = 'ssl';
322
- ageConfidence = 'low'; // SSL can be renewed, not reliable for age
323
- }
324
-
325
- // Determine maturity level
326
- let maturityLevel: SiteMaturity;
327
- if (estimatedAgeDays === null || estimatedAgeDays < 90) {
328
- maturityLevel = 'new';
329
- } else if (estimatedAgeDays < 365) {
330
- maturityLevel = 'growing';
331
- } else if (estimatedAgeDays < 730) {
332
- maturityLevel = 'established';
333
- } else {
334
- maturityLevel = 'mature';
335
- }
336
-
337
- // Override based on other signals
338
- if (htmlSignals.hasEstablishedBrand && indexedPages > 100) {
339
- if (maturityLevel === 'new') maturityLevel = 'growing';
340
- if (maturityLevel === 'growing') maturityLevel = 'established';
341
- }
342
-
343
- // Authority indicators (simplified without external API)
344
- const authorityIndicators = {
345
- hasBacklinks: wayback.snapshots > 5, // Rough proxy
346
- estimatedBacklinks: wayback.snapshots * 2, // Very rough estimate
347
- hasIndexedPages: indexedPages > 0,
348
- indexedPagesEstimate: indexedPages,
349
- hasBrandMentions: htmlSignals.hasEstablishedBrand,
350
- sslAge,
351
- };
352
-
353
- // Content metrics
354
- const contentToAuthorityRatio: 'balanced' | 'content-heavy' | 'authority-heavy' =
355
- indexedPages > 50 && !authorityIndicators.hasBacklinks
356
- ? 'content-heavy'
357
- : indexedPages < 10 && authorityIndicators.hasBacklinks
358
- ? 'authority-heavy'
359
- : 'balanced';
360
-
361
- const contentMetrics: SiteMaturityData['contentMetrics'] = {
362
- pageCount: indexedPages,
363
- hasMultipleContentTypes: htmlSignals.hasMultipleContentTypes,
364
- hasBlog: htmlSignals.hasBlog,
365
- contentToAuthorityRatio,
366
- };
367
-
368
- // Get strategy recommendations
369
- const { strategy, recommendations } = determineStrategy(maturityLevel, authorityIndicators, contentMetrics);
370
-
371
- // Generate issues based on maturity
372
- if (maturityLevel === 'new') {
373
- issues.push({
374
- code: 'NEW_SITE_STRATEGY',
375
- severity: 'notice',
376
- category: 'content',
377
- title: 'New website detected - Authority-first strategy recommended',
378
- description:
379
- 'Your site appears to be new (<90 days). Standard SEO advice won\'t work well for new sites.',
380
- impact:
381
- 'Creating lots of content without authority is wasted effort. Content from new sites rarely ranks.',
382
- howToFix:
383
- 'Focus on building 10+ quality backlinks to ONE great page before expanding content. See strategic recommendations.',
384
- affectedUrls: [url],
385
- details: {
386
- estimatedAge: estimatedAgeDays,
387
- recommendedStrategy: strategy,
388
- recommendations,
389
- },
390
- });
391
- }
392
-
393
- if (contentToAuthorityRatio === 'content-heavy') {
394
- issues.push({
395
- code: 'CONTENT_AUTHORITY_IMBALANCE',
396
- severity: 'warning',
397
- category: 'content',
398
- title: 'Content-to-authority imbalance',
399
- description: `Site has ~${indexedPages} pages but limited backlink signals. Content is unlikely to rank.`,
400
- impact: 'Most of your content may be invisible to search engines due to low domain authority.',
401
- howToFix:
402
- 'Stop publishing new content. Focus 100% on link building until you see ranking improvements.',
403
- affectedUrls: [url],
404
- details: {
405
- indexedPages,
406
- contentToAuthorityRatio,
407
- maturityLevel,
408
- },
409
- });
410
- }
411
-
412
- if (maturityLevel === 'growing' && !htmlSignals.hasBlog) {
413
- issues.push({
414
- code: 'GROWING_SITE_NO_BLOG',
415
- severity: 'notice',
416
- category: 'content',
417
- title: 'Growing site without blog/content hub',
418
- description: 'Site is in growth phase but lacks a blog or content section.',
419
- impact: 'Blog content is essential for attracting backlinks and building topical authority.',
420
- howToFix: 'Create a blog section with linkable content assets (guides, research, tools).',
421
- affectedUrls: [url],
422
- });
423
- }
424
-
425
- return {
426
- issues,
427
- data: {
428
- estimatedAge: {
429
- days: estimatedAgeDays,
430
- source: ageSource,
431
- confidence: ageConfidence,
432
- },
433
- maturityLevel,
434
- authorityIndicators,
435
- contentMetrics,
436
- recommendedStrategy: strategy,
437
- strategicRecommendations: recommendations,
438
- },
439
- };
440
- }
441
-
442
- /**
443
- * Quick check for site age category (for conditional audit logic)
444
- */
445
- export function getSiteAgeCategory(
446
- estimatedAgeDays: number | null
447
- ): 'brand-new' | 'new' | 'adolescent' | 'established' | 'veteran' {
448
- if (estimatedAgeDays === null || estimatedAgeDays < 30) return 'brand-new';
449
- if (estimatedAgeDays < 180) return 'new';
450
- if (estimatedAgeDays < 365) return 'adolescent';
451
- if (estimatedAgeDays < 1095) return 'established'; // 3 years
452
- return 'veteran';
453
- }