@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,265 +0,0 @@
1
- // Google Analytics 4 Integration
2
- // Auto-inject GA4 tracking code into web projects
3
-
4
- import * as fs from 'fs';
5
- import * as path from 'path';
6
-
7
- export interface GA4Config {
8
- measurementId: string; // G-XXXXXXXXXX
9
- }
10
-
11
- export interface InjectionResult {
12
- success: boolean;
13
- file?: string;
14
- message: string;
15
- code?: string;
16
- }
17
-
18
- /**
19
- * Generate GA4 tracking script
20
- */
21
- export function generateGA4Script(config: GA4Config): string {
22
- return `<!-- Google Analytics 4 -->
23
- <script async src="https://www.googletagmanager.com/gtag/js?id=${config.measurementId}"></script>
24
- <script>
25
- window.dataLayer = window.dataLayer || [];
26
- function gtag(){dataLayer.push(arguments);}
27
- gtag('js', new Date());
28
- gtag('config', '${config.measurementId}');
29
- </script>`;
30
- }
31
-
32
- /**
33
- * Generate GA4 for React/Next.js (component-based)
34
- */
35
- export function generateGA4ReactComponent(config: GA4Config): string {
36
- return `// components/GoogleAnalytics.tsx
37
- import Script from 'next/script';
38
-
39
- export function GoogleAnalytics() {
40
- const measurementId = '${config.measurementId}';
41
-
42
- return (
43
- <>
44
- <Script
45
- src={\`https://www.googletagmanager.com/gtag/js?id=\${measurementId}\`}
46
- strategy="afterInteractive"
47
- />
48
- <Script id="google-analytics" strategy="afterInteractive">
49
- {\`
50
- window.dataLayer = window.dataLayer || [];
51
- function gtag(){dataLayer.push(arguments);}
52
- gtag('js', new Date());
53
- gtag('config', '\${measurementId}');
54
- \`}
55
- </Script>
56
- </>
57
- );
58
- }`;
59
- }
60
-
61
- /**
62
- * Generate GA4 for Vite/vanilla (index.html injection)
63
- */
64
- export function generateGA4ViteScript(config: GA4Config): string {
65
- return ` <!-- Google Analytics 4 -->
66
- <script async src="https://www.googletagmanager.com/gtag/js?id=${config.measurementId}"></script>
67
- <script>
68
- window.dataLayer = window.dataLayer || [];
69
- function gtag(){dataLayer.push(arguments);}
70
- gtag('js', new Date());
71
- gtag('config', '${config.measurementId}');
72
- </script>`;
73
- }
74
-
75
- /**
76
- * Simple framework detection for tracking injection
77
- */
78
- function detectFrameworkSimple(projectPath: string): string {
79
- // Check for Next.js
80
- if (fs.existsSync(path.join(projectPath, 'next.config.js')) ||
81
- fs.existsSync(path.join(projectPath, 'next.config.ts')) ||
82
- fs.existsSync(path.join(projectPath, 'next.config.mjs'))) {
83
- return 'nextjs';
84
- }
85
-
86
- // Check for Vite
87
- if (fs.existsSync(path.join(projectPath, 'vite.config.js')) ||
88
- fs.existsSync(path.join(projectPath, 'vite.config.ts'))) {
89
- return 'vite';
90
- }
91
-
92
- // Check for plain HTML
93
- if (fs.existsSync(path.join(projectPath, 'index.html'))) {
94
- return 'html';
95
- }
96
-
97
- // Check for React (CRA)
98
- const pkgPath = path.join(projectPath, 'package.json');
99
- if (fs.existsSync(pkgPath)) {
100
- try {
101
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
102
- if (pkg.dependencies?.react || pkg.devDependencies?.react) {
103
- return 'react';
104
- }
105
- } catch {
106
- // Ignore parse errors
107
- }
108
- }
109
-
110
- return 'unknown';
111
- }
112
-
113
- /**
114
- * Auto-detect framework and inject GA4
115
- */
116
- export async function injectGA4(projectPath: string, config: GA4Config): Promise<InjectionResult> {
117
- const framework = detectFrameworkSimple(projectPath);
118
-
119
- switch (framework) {
120
- case 'nextjs':
121
- return injectGA4NextJs(projectPath, config);
122
- case 'vite':
123
- case 'react':
124
- return injectGA4Vite(projectPath, config);
125
- case 'html':
126
- return injectGA4Html(projectPath, config);
127
- default:
128
- return {
129
- success: false,
130
- message: `Unsupported framework: ${framework}. Please manually add GA4.`,
131
- code: generateGA4Script(config),
132
- };
133
- }
134
- }
135
-
136
- async function injectGA4NextJs(projectPath: string, config: GA4Config): Promise<InjectionResult> {
137
- // Check for app directory (App Router) or pages directory (Pages Router)
138
- const appLayoutPath = path.join(projectPath, 'app', 'layout.tsx');
139
- const pagesAppPath = path.join(projectPath, 'pages', '_app.tsx');
140
- const srcAppLayoutPath = path.join(projectPath, 'src', 'app', 'layout.tsx');
141
- const srcPagesAppPath = path.join(projectPath, 'src', 'pages', '_app.tsx');
142
-
143
- // Try App Router first
144
- for (const layoutPath of [appLayoutPath, srcAppLayoutPath]) {
145
- if (fs.existsSync(layoutPath)) {
146
- const content = fs.readFileSync(layoutPath, 'utf-8');
147
-
148
- // Check if GA4 already exists
149
- if (content.includes('googletagmanager.com/gtag')) {
150
- return { success: true, file: layoutPath, message: 'GA4 already installed' };
151
- }
152
-
153
- // Create GoogleAnalytics component
154
- const componentsDir = path.join(path.dirname(layoutPath), '..', 'components');
155
- if (!fs.existsSync(componentsDir)) {
156
- fs.mkdirSync(componentsDir, { recursive: true });
157
- }
158
-
159
- const gaComponentPath = path.join(componentsDir, 'GoogleAnalytics.tsx');
160
- fs.writeFileSync(gaComponentPath, generateGA4ReactComponent(config));
161
-
162
- // Update layout to import and use component
163
- const importStatement = `import { GoogleAnalytics } from '@/components/GoogleAnalytics';\n`;
164
- const componentUsage = '<GoogleAnalytics />';
165
-
166
- // Add import at top
167
- let newContent = content;
168
- if (!newContent.includes('GoogleAnalytics')) {
169
- // Find first import or add at top
170
- const importMatch = newContent.match(/^import .+$/m);
171
- if (importMatch) {
172
- newContent = newContent.replace(importMatch[0], importMatch[0] + '\n' + importStatement);
173
- } else {
174
- newContent = importStatement + newContent;
175
- }
176
-
177
- // Add component inside <head> or <body>
178
- if (newContent.includes('<head>')) {
179
- newContent = newContent.replace('<head>', `<head>\n ${componentUsage}`);
180
- } else if (newContent.includes('<body')) {
181
- newContent = newContent.replace(/<body([^>]*)>/, `<body$1>\n ${componentUsage}`);
182
- }
183
-
184
- fs.writeFileSync(layoutPath, newContent);
185
- }
186
-
187
- return {
188
- success: true,
189
- file: layoutPath,
190
- message: `GA4 component created at ${gaComponentPath} and imported in layout`,
191
- };
192
- }
193
- }
194
-
195
- // Try Pages Router
196
- for (const appPath of [pagesAppPath, srcPagesAppPath]) {
197
- if (fs.existsSync(appPath)) {
198
- return {
199
- success: false,
200
- file: appPath,
201
- message: 'Pages Router detected. Please manually add GA4 to _app.tsx',
202
- code: generateGA4ReactComponent(config),
203
- };
204
- }
205
- }
206
-
207
- return {
208
- success: false,
209
- message: 'Could not find Next.js layout or _app file',
210
- code: generateGA4ReactComponent(config),
211
- };
212
- }
213
-
214
- async function injectGA4Vite(projectPath: string, config: GA4Config): Promise<InjectionResult> {
215
- // Look for index.html
216
- const indexPaths = [
217
- path.join(projectPath, 'index.html'),
218
- path.join(projectPath, 'public', 'index.html'),
219
- path.join(projectPath, 'src', 'index.html'),
220
- ];
221
-
222
- for (const indexPath of indexPaths) {
223
- if (fs.existsSync(indexPath)) {
224
- let content = fs.readFileSync(indexPath, 'utf-8');
225
-
226
- // Check if already installed
227
- if (content.includes('googletagmanager.com/gtag')) {
228
- return { success: true, file: indexPath, message: 'GA4 already installed' };
229
- }
230
-
231
- // Inject before </head>
232
- const ga4Script = generateGA4ViteScript(config);
233
- content = content.replace('</head>', `${ga4Script}\n </head>`);
234
-
235
- fs.writeFileSync(indexPath, content);
236
- return {
237
- success: true,
238
- file: indexPath,
239
- message: `GA4 injected into ${indexPath}`,
240
- };
241
- }
242
- }
243
-
244
- return {
245
- success: false,
246
- message: 'Could not find index.html',
247
- code: generateGA4Script(config),
248
- };
249
- }
250
-
251
- async function injectGA4Html(projectPath: string, config: GA4Config): Promise<InjectionResult> {
252
- return injectGA4Vite(projectPath, config); // Same logic
253
- }
254
-
255
- /**
256
- * Generate environment variable template for GA4
257
- */
258
- export function generateGA4EnvTemplate(): string {
259
- return `# Google Analytics 4
260
- # Get your Measurement ID from: https://analytics.google.com
261
- # Go to: Admin > Data Streams > Your Stream > Measurement ID
262
- VITE_GA4_MEASUREMENT_ID=G-XXXXXXXXXX
263
- # or for Next.js:
264
- NEXT_PUBLIC_GA4_MEASUREMENT_ID=G-XXXXXXXXXX`;
265
- }
@@ -1,45 +0,0 @@
1
- // Tracking & Monitoring Module
2
- // Google Analytics, Search Console integration, and automated reporting
3
-
4
- // Google Analytics 4
5
- export {
6
- generateGA4Script,
7
- generateGA4ReactComponent,
8
- generateGA4ViteScript,
9
- generateGA4EnvTemplate,
10
- injectGA4,
11
- type GA4Config,
12
- type InjectionResult,
13
- } from './google-analytics.js';
14
-
15
- // Google Search Console
16
- export {
17
- generateGSCVerificationTag,
18
- injectGSCVerification,
19
- buildGSCApiRequest,
20
- parseGSCResponse,
21
- identifyQuickWins,
22
- comparePeriods,
23
- getGSCSetupInstructions,
24
- type GSCConfig,
25
- type GSCCredentials,
26
- type GSCQueryResult,
27
- type GSCPerformanceData,
28
- type QuickWin,
29
- } from './search-console.js';
30
-
31
- // GitHub Action
32
- export {
33
- generateWorkflow,
34
- generateSecretsDoc,
35
- generateGitHubActionSetup,
36
- writeGitHubActionFiles,
37
- type WorkflowConfig,
38
- } from './github-action.js';
39
-
40
- // Report Generator
41
- export {
42
- generateMarkdownReport,
43
- generateJsonReport,
44
- type ReportData,
45
- } from './report-generator.js';
@@ -1,386 +0,0 @@
1
- // SEO Report Generator
2
- // Creates formatted reports for GitHub Issues and dashboards
3
-
4
- import type { AuditReport, AuditIssue } from '../audit/index.js';
5
- import type { GSCPerformanceData, QuickWin } from './search-console.js';
6
-
7
- export interface ReportData {
8
- siteUrl: string;
9
- generatedAt: string;
10
- audit?: AuditReport;
11
- tracking?: {
12
- current: GSCPerformanceData;
13
- previous?: GSCPerformanceData;
14
- quickWins: QuickWin[];
15
- };
16
- comparison?: {
17
- improved: any[];
18
- declined: any[];
19
- newKeywords: any[];
20
- lostKeywords: any[];
21
- summary: {
22
- clicksChange: number;
23
- impressionsChange: number;
24
- avgPositionChange: number;
25
- };
26
- };
27
- }
28
-
29
- /**
30
- * Generate comprehensive markdown report
31
- */
32
- export function generateMarkdownReport(data: ReportData): string {
33
- const lines: string[] = [];
34
- const date = new Date(data.generatedAt).toLocaleDateString('en-US', {
35
- weekday: 'long',
36
- year: 'numeric',
37
- month: 'long',
38
- day: 'numeric',
39
- });
40
-
41
- lines.push(`# 📊 SEO Report: ${data.siteUrl}`);
42
- lines.push(`> Generated: ${date}`);
43
- lines.push('');
44
-
45
- // Executive Summary
46
- lines.push('## 📋 Executive Summary');
47
- lines.push('');
48
- lines.push(generateExecutiveSummary(data));
49
- lines.push('');
50
-
51
- // Health Score (if audit data)
52
- if (data.audit) {
53
- lines.push('## 🏥 Site Health');
54
- lines.push('');
55
- lines.push(generateHealthSection(data.audit));
56
- lines.push('');
57
- }
58
-
59
- // Traffic & Rankings (if tracking data)
60
- if (data.tracking) {
61
- lines.push('## 📈 Traffic & Rankings');
62
- lines.push('');
63
- lines.push(generateTrackingSection(data.tracking, data.comparison));
64
- lines.push('');
65
- }
66
-
67
- // Quick Wins
68
- if (data.tracking?.quickWins && data.tracking.quickWins.length > 0) {
69
- lines.push('## 🎯 Quick Wins');
70
- lines.push('');
71
- lines.push(generateQuickWinsSection(data.tracking.quickWins));
72
- lines.push('');
73
- }
74
-
75
- // Issues to Fix (if audit data)
76
- if (data.audit && data.audit.issues.length > 0) {
77
- lines.push('## 🔧 Issues to Fix');
78
- lines.push('');
79
- lines.push(generateIssuesSection(data.audit));
80
- lines.push('');
81
- }
82
-
83
- // Action Items
84
- lines.push('## ✅ Recommended Actions');
85
- lines.push('');
86
- lines.push(generateActionItems(data));
87
- lines.push('');
88
-
89
- // Footer
90
- lines.push('---');
91
- lines.push('');
92
- lines.push('*Generated by [SEO Autopilot](https://github.com/seo-autopilot) 🤖*');
93
-
94
- return lines.join('\n');
95
- }
96
-
97
- function generateExecutiveSummary(data: ReportData): string {
98
- const lines: string[] = [];
99
-
100
- if (data.audit) {
101
- const score = data.audit.healthScore.overall;
102
- const emoji = score >= 80 ? '🟢' : score >= 60 ? '🟡' : '🔴';
103
- const totalIssues = data.audit.summary.errors + data.audit.summary.warnings + data.audit.summary.notices;
104
- const totalChecks = totalIssues + data.audit.summary.passed;
105
- lines.push(`| Metric | Value |`);
106
- lines.push(`|--------|-------|`);
107
- lines.push(`| ${emoji} Health Score | **${score}/100** |`);
108
- lines.push(`| Issues Found | ${data.audit.issues.length} |`);
109
- lines.push(`| Checks Passed | ${data.audit.summary.passed}/${totalChecks} |`);
110
- }
111
-
112
- if (data.tracking) {
113
- if (!data.audit) {
114
- lines.push(`| Metric | Value |`);
115
- lines.push(`|--------|-------|`);
116
- }
117
- lines.push(`| Total Clicks | ${data.tracking.current.totalClicks.toLocaleString()} |`);
118
- lines.push(`| Total Impressions | ${data.tracking.current.totalImpressions.toLocaleString()} |`);
119
- lines.push(`| Avg Position | ${data.tracking.current.avgPosition.toFixed(1)} |`);
120
- lines.push(`| Avg CTR | ${(data.tracking.current.avgCtr * 100).toFixed(2)}% |`);
121
- }
122
-
123
- if (data.comparison) {
124
- lines.push('');
125
- lines.push('### Week-over-Week Changes');
126
- lines.push('');
127
-
128
- const clicksChange = data.comparison.summary.clicksChange;
129
- const impressionsChange = data.comparison.summary.impressionsChange;
130
- const positionChange = data.comparison.summary.avgPositionChange;
131
-
132
- const clicksEmoji = clicksChange > 0 ? '📈' : clicksChange < 0 ? '📉' : '➡️';
133
- const impressionsEmoji = impressionsChange > 0 ? '📈' : impressionsChange < 0 ? '📉' : '➡️';
134
- const positionEmoji = positionChange < 0 ? '📈' : positionChange > 0 ? '📉' : '➡️'; // Lower is better
135
-
136
- lines.push(`- ${clicksEmoji} Clicks: ${clicksChange >= 0 ? '+' : ''}${clicksChange.toLocaleString()}`);
137
- lines.push(`- ${impressionsEmoji} Impressions: ${impressionsChange >= 0 ? '+' : ''}${impressionsChange.toLocaleString()}`);
138
- lines.push(`- ${positionEmoji} Avg Position: ${positionChange >= 0 ? '+' : ''}${positionChange.toFixed(1)}`);
139
- }
140
-
141
- return lines.join('\n');
142
- }
143
-
144
- function generateHealthSection(audit: AuditReport): string {
145
- const lines: string[] = [];
146
-
147
- // Visual score bar
148
- const score = audit.healthScore.overall;
149
- const filled = Math.round(score / 10);
150
- const empty = 10 - filled;
151
- const bar = '█'.repeat(filled) + '░'.repeat(empty);
152
-
153
- lines.push(`### Score: ${score}/100`);
154
- lines.push('');
155
- lines.push(`\`${bar}\``);
156
- lines.push('');
157
-
158
- // Category breakdown
159
- const categories = new Map<string, { passed: number; total: number }>();
160
-
161
- for (const issue of audit.issues) {
162
- const cat = issue.category;
163
- if (!categories.has(cat)) {
164
- categories.set(cat, { passed: 0, total: 0 });
165
- }
166
- categories.get(cat)!.total++;
167
- }
168
-
169
- if (categories.size > 0) {
170
- lines.push('| Category | Issues |');
171
- lines.push('|----------|--------|');
172
-
173
- for (const [category, counts] of categories) {
174
- const icon = counts.total === 0 ? '✅' : counts.total <= 2 ? '⚠️' : '❌';
175
- lines.push(`| ${icon} ${category} | ${counts.total} |`);
176
- }
177
- }
178
-
179
- return lines.join('\n');
180
- }
181
-
182
- function generateTrackingSection(
183
- tracking: ReportData['tracking'],
184
- comparison?: ReportData['comparison']
185
- ): string {
186
- if (!tracking) return '';
187
-
188
- const lines: string[] = [];
189
-
190
- // Top performing queries
191
- lines.push('### Top Performing Queries');
192
- lines.push('');
193
- lines.push('| Query | Clicks | Impressions | Position | CTR |');
194
- lines.push('|-------|--------|-------------|----------|-----|');
195
-
196
- const topQueries = tracking.current.queries
197
- .sort((a, b) => b.clicks - a.clicks)
198
- .slice(0, 10);
199
-
200
- for (const q of topQueries) {
201
- lines.push(`| ${truncate(q.query, 40)} | ${q.clicks} | ${q.impressions} | ${q.position.toFixed(1)} | ${(q.ctr * 100).toFixed(1)}% |`);
202
- }
203
-
204
- // Comparison data
205
- if (comparison) {
206
- if (comparison.improved.length > 0) {
207
- lines.push('');
208
- lines.push('### 📈 Improved Rankings');
209
- lines.push('');
210
- for (const q of comparison.improved.slice(0, 5)) {
211
- lines.push(`- **${q.query}**: Moved up to position ${q.position.toFixed(1)}`);
212
- }
213
- }
214
-
215
- if (comparison.declined.length > 0) {
216
- lines.push('');
217
- lines.push('### 📉 Declined Rankings');
218
- lines.push('');
219
- for (const q of comparison.declined.slice(0, 5)) {
220
- lines.push(`- **${q.query}**: Dropped to position ${q.position.toFixed(1)}`);
221
- }
222
- }
223
-
224
- if (comparison.newKeywords.length > 0) {
225
- lines.push('');
226
- lines.push('### 🆕 New Keywords');
227
- lines.push('');
228
- for (const q of comparison.newKeywords.slice(0, 5)) {
229
- lines.push(`- **${q.query}**: Position ${q.position.toFixed(1)} (${q.impressions} impressions)`);
230
- }
231
- }
232
- }
233
-
234
- return lines.join('\n');
235
- }
236
-
237
- function generateQuickWinsSection(quickWins: QuickWin[]): string {
238
- const lines: string[] = [];
239
-
240
- lines.push('These are high-impact opportunities requiring minimal effort:');
241
- lines.push('');
242
-
243
- for (const win of quickWins.slice(0, 10)) {
244
- const typeIcon = win.opportunity === 'page-1-close' ? '🎯' :
245
- win.opportunity === 'low-ctr' ? '📝' : '⬆️';
246
-
247
- lines.push(`### ${typeIcon} ${truncate(win.query, 50)}`);
248
- lines.push('');
249
- lines.push(`- **Current Position**: ${win.currentPosition.toFixed(1)}`);
250
- lines.push(`- **Impressions**: ${win.impressions.toLocaleString()}/month`);
251
- lines.push(`- **Current CTR**: ${(win.ctr * 100).toFixed(1)}%`);
252
- lines.push(`- **Potential Gain**: +${win.potentialGain} clicks/month`);
253
- lines.push(`- **Action**: ${win.suggestedAction}`);
254
- lines.push('');
255
- }
256
-
257
- return lines.join('\n');
258
- }
259
-
260
- function generateIssuesSection(audit: AuditReport): string {
261
- const lines: string[] = [];
262
-
263
- // Group by severity
264
- const errors = audit.issues.filter((i: AuditIssue) => i.severity === 'error');
265
- const warnings = audit.issues.filter((i: AuditIssue) => i.severity === 'warning');
266
- const notices = audit.issues.filter((i: AuditIssue) => i.severity === 'notice');
267
-
268
- if (errors.length > 0) {
269
- lines.push('### ❌ Errors (Fix Immediately)');
270
- lines.push('');
271
- for (const issue of errors.slice(0, 10)) {
272
- lines.push(`- **${issue.code}**: ${issue.title}`);
273
- if (issue.affectedUrls && issue.affectedUrls.length > 0) {
274
- lines.push(` - URL: \`${issue.affectedUrls[0]}\``);
275
- }
276
- }
277
- lines.push('');
278
- }
279
-
280
- if (warnings.length > 0) {
281
- lines.push('### ⚠️ Warnings (Should Fix)');
282
- lines.push('');
283
- for (const issue of warnings.slice(0, 10)) {
284
- lines.push(`- **${issue.code}**: ${issue.title}`);
285
- }
286
- lines.push('');
287
- }
288
-
289
- if (notices.length > 0) {
290
- lines.push('<details>');
291
- lines.push('<summary>📝 Notices (Consider Fixing) - ' + notices.length + ' items</summary>');
292
- lines.push('');
293
- for (const issue of notices.slice(0, 20)) {
294
- lines.push(`- ${issue.code}: ${issue.title}`);
295
- }
296
- lines.push('</details>');
297
- lines.push('');
298
- }
299
-
300
- return lines.join('\n');
301
- }
302
-
303
- function generateActionItems(data: ReportData): string {
304
- const lines: string[] = [];
305
- const actions: string[] = [];
306
-
307
- // From audit issues
308
- if (data.audit) {
309
- const errors = data.audit.issues.filter((i: AuditIssue) => i.severity === 'error');
310
- if (errors.length > 0) {
311
- actions.push(`Fix ${errors.length} critical SEO errors`);
312
- }
313
-
314
- const missingMeta = data.audit.issues.filter((i: AuditIssue) =>
315
- i.code.includes('TITLE') || i.code.includes('META')
316
- );
317
- if (missingMeta.length > 0) {
318
- actions.push(`Add missing meta tags on ${missingMeta.length} pages`);
319
- }
320
- }
321
-
322
- // From quick wins
323
- if (data.tracking?.quickWins) {
324
- const pageOneClose = data.tracking.quickWins.filter(w => w.opportunity === 'page-1-close');
325
- if (pageOneClose.length > 0) {
326
- actions.push(`Optimize ${pageOneClose.length} keywords that are almost on page 1`);
327
- }
328
-
329
- const lowCtr = data.tracking.quickWins.filter(w => w.opportunity === 'low-ctr');
330
- if (lowCtr.length > 0) {
331
- actions.push(`Improve titles/descriptions for ${lowCtr.length} low-CTR pages`);
332
- }
333
- }
334
-
335
- // From comparison
336
- if (data.comparison?.declined && data.comparison.declined.length > 0) {
337
- actions.push(`Investigate ${data.comparison.declined.length} keywords with declining rankings`);
338
- }
339
-
340
- if (actions.length === 0) {
341
- actions.push('Continue monitoring - no urgent actions needed');
342
- }
343
-
344
- lines.push('Priority order:');
345
- lines.push('');
346
- for (let i = 0; i < actions.length; i++) {
347
- lines.push(`${i + 1}. [ ] ${actions[i]}`);
348
- }
349
-
350
- return lines.join('\n');
351
- }
352
-
353
- function truncate(str: string, maxLength: number): string {
354
- if (str.length <= maxLength) return str;
355
- return str.slice(0, maxLength - 3) + '...';
356
- }
357
-
358
- /**
359
- * Generate JSON report for API/dashboard
360
- */
361
- export function generateJsonReport(data: ReportData): object {
362
- return {
363
- meta: {
364
- siteUrl: data.siteUrl,
365
- generatedAt: data.generatedAt,
366
- version: '1.0',
367
- },
368
- health: data.audit ? {
369
- score: data.audit.healthScore.overall,
370
- issueCount: data.audit.issues.length,
371
- passed: data.audit.summary.passed,
372
- errors: data.audit.summary.errors,
373
- warnings: data.audit.summary.warnings,
374
- notices: data.audit.summary.notices,
375
- } : null,
376
- traffic: data.tracking ? {
377
- clicks: data.tracking.current.totalClicks,
378
- impressions: data.tracking.current.totalImpressions,
379
- avgPosition: data.tracking.current.avgPosition,
380
- avgCtr: data.tracking.current.avgCtr,
381
- } : null,
382
- quickWins: data.tracking?.quickWins || [],
383
- issues: data.audit?.issues || [],
384
- comparison: data.comparison || null,
385
- };
386
- }