@rankcli/agent-runtime 0.0.1

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 (178) hide show
  1. package/README.md +242 -0
  2. package/dist/analyzer-2CSWIQGD.mjs +6 -0
  3. package/dist/chunk-YNZYHEYM.mjs +774 -0
  4. package/dist/index.d.mts +4012 -0
  5. package/dist/index.d.ts +4012 -0
  6. package/dist/index.js +29672 -0
  7. package/dist/index.mjs +28602 -0
  8. package/package.json +53 -0
  9. package/scripts/build-deno.ts +134 -0
  10. package/src/audit/ai/analyzer.ts +347 -0
  11. package/src/audit/ai/index.ts +29 -0
  12. package/src/audit/ai/prompts/content-analysis.ts +271 -0
  13. package/src/audit/ai/types.ts +179 -0
  14. package/src/audit/checks/additional-checks.ts +439 -0
  15. package/src/audit/checks/ai-citation-worthiness.ts +399 -0
  16. package/src/audit/checks/ai-content-structure.ts +325 -0
  17. package/src/audit/checks/ai-readiness.ts +339 -0
  18. package/src/audit/checks/anchor-text.ts +179 -0
  19. package/src/audit/checks/answer-conciseness.ts +322 -0
  20. package/src/audit/checks/asset-minification.ts +270 -0
  21. package/src/audit/checks/bing-optimization.ts +206 -0
  22. package/src/audit/checks/brand-mention-optimization.ts +349 -0
  23. package/src/audit/checks/caching-headers.ts +305 -0
  24. package/src/audit/checks/canonical-advanced.ts +150 -0
  25. package/src/audit/checks/canonical-domain.ts +196 -0
  26. package/src/audit/checks/citation-quality.ts +358 -0
  27. package/src/audit/checks/client-rendering.ts +542 -0
  28. package/src/audit/checks/color-contrast.ts +342 -0
  29. package/src/audit/checks/content-freshness.ts +170 -0
  30. package/src/audit/checks/content-science.ts +589 -0
  31. package/src/audit/checks/conversion-elements.ts +526 -0
  32. package/src/audit/checks/crawlability.ts +220 -0
  33. package/src/audit/checks/directory-listing.ts +172 -0
  34. package/src/audit/checks/dom-analysis.ts +191 -0
  35. package/src/audit/checks/dom-size.ts +246 -0
  36. package/src/audit/checks/duplicate-content.ts +194 -0
  37. package/src/audit/checks/eeat-signals.ts +990 -0
  38. package/src/audit/checks/entity-seo.ts +396 -0
  39. package/src/audit/checks/featured-snippet.ts +473 -0
  40. package/src/audit/checks/freshness-signals.ts +443 -0
  41. package/src/audit/checks/funnel-intent.ts +463 -0
  42. package/src/audit/checks/hreflang.ts +174 -0
  43. package/src/audit/checks/html-compliance.ts +302 -0
  44. package/src/audit/checks/image-dimensions.ts +167 -0
  45. package/src/audit/checks/images.ts +160 -0
  46. package/src/audit/checks/indexnow.ts +275 -0
  47. package/src/audit/checks/interactive-tools.ts +475 -0
  48. package/src/audit/checks/internal-link-graph.ts +436 -0
  49. package/src/audit/checks/keyword-analysis.ts +239 -0
  50. package/src/audit/checks/keyword-cannibalization.ts +385 -0
  51. package/src/audit/checks/keyword-placement.ts +471 -0
  52. package/src/audit/checks/links.ts +203 -0
  53. package/src/audit/checks/llms-txt.ts +224 -0
  54. package/src/audit/checks/local-seo.ts +296 -0
  55. package/src/audit/checks/mobile.ts +167 -0
  56. package/src/audit/checks/modern-images.ts +226 -0
  57. package/src/audit/checks/navboost-signals.ts +395 -0
  58. package/src/audit/checks/on-page.ts +209 -0
  59. package/src/audit/checks/page-resources.ts +285 -0
  60. package/src/audit/checks/pagination.ts +180 -0
  61. package/src/audit/checks/performance.ts +153 -0
  62. package/src/audit/checks/platform-presence.ts +580 -0
  63. package/src/audit/checks/redirect-analysis.ts +153 -0
  64. package/src/audit/checks/redirect-chain.ts +389 -0
  65. package/src/audit/checks/resource-hints.ts +420 -0
  66. package/src/audit/checks/responsive-css.ts +247 -0
  67. package/src/audit/checks/responsive-images.ts +396 -0
  68. package/src/audit/checks/review-ecosystem.ts +415 -0
  69. package/src/audit/checks/robots-validation.ts +373 -0
  70. package/src/audit/checks/security-headers.ts +172 -0
  71. package/src/audit/checks/security.ts +144 -0
  72. package/src/audit/checks/serp-preview.ts +251 -0
  73. package/src/audit/checks/site-maturity.ts +444 -0
  74. package/src/audit/checks/social-meta.test.ts +275 -0
  75. package/src/audit/checks/social-meta.ts +134 -0
  76. package/src/audit/checks/soft-404.ts +151 -0
  77. package/src/audit/checks/structured-data.ts +238 -0
  78. package/src/audit/checks/tech-detection.ts +496 -0
  79. package/src/audit/checks/topical-clusters.ts +435 -0
  80. package/src/audit/checks/tracker-bloat.ts +462 -0
  81. package/src/audit/checks/tracking-verification.test.ts +371 -0
  82. package/src/audit/checks/tracking-verification.ts +636 -0
  83. package/src/audit/checks/url-safety.ts +682 -0
  84. package/src/audit/deno-entry.ts +66 -0
  85. package/src/audit/discovery/index.ts +15 -0
  86. package/src/audit/discovery/link-crawler.ts +232 -0
  87. package/src/audit/discovery/repo-routes.ts +347 -0
  88. package/src/audit/engine.ts +620 -0
  89. package/src/audit/fixes/index.ts +209 -0
  90. package/src/audit/fixes/social-meta-fixes.test.ts +329 -0
  91. package/src/audit/fixes/social-meta-fixes.ts +463 -0
  92. package/src/audit/index.ts +74 -0
  93. package/src/audit/runner.test.ts +299 -0
  94. package/src/audit/runner.ts +130 -0
  95. package/src/audit/types.ts +1953 -0
  96. package/src/content/featured-snippet.ts +367 -0
  97. package/src/content/generator.test.ts +534 -0
  98. package/src/content/generator.ts +501 -0
  99. package/src/content/headline.ts +317 -0
  100. package/src/content/index.ts +62 -0
  101. package/src/content/intent.ts +258 -0
  102. package/src/content/keyword-density.ts +349 -0
  103. package/src/content/readability.ts +262 -0
  104. package/src/executor.ts +336 -0
  105. package/src/fixer.ts +416 -0
  106. package/src/frameworks/detector.test.ts +248 -0
  107. package/src/frameworks/detector.ts +371 -0
  108. package/src/frameworks/index.ts +68 -0
  109. package/src/frameworks/recipes/angular.yaml +171 -0
  110. package/src/frameworks/recipes/astro.yaml +206 -0
  111. package/src/frameworks/recipes/django.yaml +180 -0
  112. package/src/frameworks/recipes/laravel.yaml +137 -0
  113. package/src/frameworks/recipes/nextjs.yaml +268 -0
  114. package/src/frameworks/recipes/nuxt.yaml +175 -0
  115. package/src/frameworks/recipes/rails.yaml +188 -0
  116. package/src/frameworks/recipes/react.yaml +202 -0
  117. package/src/frameworks/recipes/sveltekit.yaml +154 -0
  118. package/src/frameworks/recipes/vue.yaml +137 -0
  119. package/src/frameworks/recipes/wordpress.yaml +209 -0
  120. package/src/frameworks/suggestion-engine.ts +320 -0
  121. package/src/geo/geo-content.test.ts +305 -0
  122. package/src/geo/geo-content.ts +266 -0
  123. package/src/geo/geo-history.test.ts +473 -0
  124. package/src/geo/geo-history.ts +433 -0
  125. package/src/geo/geo-tracker.test.ts +359 -0
  126. package/src/geo/geo-tracker.ts +411 -0
  127. package/src/geo/index.ts +10 -0
  128. package/src/git/commit-helper.test.ts +261 -0
  129. package/src/git/commit-helper.ts +329 -0
  130. package/src/git/index.ts +12 -0
  131. package/src/git/pr-helper.test.ts +284 -0
  132. package/src/git/pr-helper.ts +307 -0
  133. package/src/index.ts +66 -0
  134. package/src/keywords/ai-keyword-engine.ts +1062 -0
  135. package/src/keywords/ai-summarizer.ts +387 -0
  136. package/src/keywords/ci-mode.ts +555 -0
  137. package/src/keywords/engine.ts +359 -0
  138. package/src/keywords/index.ts +151 -0
  139. package/src/keywords/llm-judge.ts +357 -0
  140. package/src/keywords/nlp-analysis.ts +706 -0
  141. package/src/keywords/prioritizer.ts +295 -0
  142. package/src/keywords/site-crawler.ts +342 -0
  143. package/src/keywords/sources/autocomplete.ts +139 -0
  144. package/src/keywords/sources/competitive-search.ts +450 -0
  145. package/src/keywords/sources/competitor-analysis.ts +374 -0
  146. package/src/keywords/sources/dataforseo.ts +206 -0
  147. package/src/keywords/sources/free-sources.ts +294 -0
  148. package/src/keywords/sources/gsc.ts +123 -0
  149. package/src/keywords/topic-grouping.ts +327 -0
  150. package/src/keywords/types.ts +144 -0
  151. package/src/keywords/wizard.ts +457 -0
  152. package/src/loader.ts +40 -0
  153. package/src/reports/index.ts +7 -0
  154. package/src/reports/report-generator.test.ts +293 -0
  155. package/src/reports/report-generator.ts +713 -0
  156. package/src/scheduler/alerts.test.ts +458 -0
  157. package/src/scheduler/alerts.ts +328 -0
  158. package/src/scheduler/index.ts +8 -0
  159. package/src/scheduler/scheduled-audit.test.ts +377 -0
  160. package/src/scheduler/scheduled-audit.ts +149 -0
  161. package/src/test/integration-test.ts +325 -0
  162. package/src/tools/analyzer.ts +373 -0
  163. package/src/tools/crawl.ts +293 -0
  164. package/src/tools/files.ts +301 -0
  165. package/src/tools/h1-fixer.ts +249 -0
  166. package/src/tools/index.ts +67 -0
  167. package/src/tracking/github-action.ts +326 -0
  168. package/src/tracking/google-analytics.ts +265 -0
  169. package/src/tracking/index.ts +45 -0
  170. package/src/tracking/report-generator.ts +386 -0
  171. package/src/tracking/search-console.ts +335 -0
  172. package/src/types.ts +134 -0
  173. package/src/utils/http.ts +302 -0
  174. package/src/wasm-adapter.ts +297 -0
  175. package/src/wasm-entry.ts +14 -0
  176. package/tsconfig.json +17 -0
  177. package/tsup.wasm.config.ts +26 -0
  178. package/vitest.config.ts +15 -0
@@ -0,0 +1,224 @@
1
+ /**
2
+ * llms.txt Check
3
+ *
4
+ * llms.txt is a proposed standard (https://llmstxt.org/) for providing
5
+ * context to Large Language Models about a website.
6
+ *
7
+ * The file is a Markdown document at /llms.txt that contains:
8
+ * - Brief description of the site/organization
9
+ * - Links to important pages
10
+ * - Optional detailed content at /llms-full.txt
11
+ *
12
+ * Format:
13
+ * # Site Name
14
+ * > Brief description
15
+ *
16
+ * ## Section
17
+ * - [Link Text](url): Description
18
+ */
19
+
20
+ import { httpGet } from '../../utils/http.js';
21
+ import type { AuditIssue } from '../types.js';
22
+
23
+ export interface LlmsTxtData {
24
+ exists: boolean;
25
+ fullVersionExists: boolean;
26
+ content?: string;
27
+ structure: {
28
+ hasTitle: boolean;
29
+ hasDescription: boolean;
30
+ hasSections: boolean;
31
+ hasLinks: boolean;
32
+ linkCount: number;
33
+ };
34
+ contentLength: number;
35
+ }
36
+
37
+ export async function analyzeLlmsTxt(
38
+ url: string
39
+ ): Promise<{ issues: AuditIssue[]; data: LlmsTxtData }> {
40
+ const issues: AuditIssue[] = [];
41
+ const parsedUrl = new URL(url);
42
+ const baseUrl = parsedUrl.origin;
43
+
44
+ // Check for llms.txt
45
+ const llmsTxtUrl = new URL('/llms.txt', baseUrl).href;
46
+ const llmsFullUrl = new URL('/llms-full.txt', baseUrl).href;
47
+
48
+ let exists = false;
49
+ let fullVersionExists = false;
50
+ let content: string | undefined;
51
+ let structure = {
52
+ hasTitle: false,
53
+ hasDescription: false,
54
+ hasSections: false,
55
+ hasLinks: false,
56
+ linkCount: 0,
57
+ };
58
+ let contentLength = 0;
59
+
60
+ try {
61
+ // Check main llms.txt
62
+ const response = await httpGet<string>(llmsTxtUrl, {
63
+ timeout: 10000,
64
+ validateStatus: () => true,
65
+ });
66
+
67
+ if (response.status === 200) {
68
+ exists = true;
69
+ content = response.data as string;
70
+ contentLength = content.length;
71
+ structure = analyzeStructure(content);
72
+ }
73
+
74
+ // Check for full version
75
+ const fullResponse = await httpGet<string>(llmsFullUrl, {
76
+ timeout: 10000,
77
+ validateStatus: () => true,
78
+ });
79
+
80
+ if (fullResponse.status === 200) {
81
+ fullVersionExists = true;
82
+ }
83
+ } catch {
84
+ // Network error, treat as not existing
85
+ }
86
+
87
+ // Generate issues
88
+ if (!exists) {
89
+ issues.push({
90
+ code: 'AI_NO_LLMS_TXT',
91
+ severity: 'notice',
92
+ category: 'ai-readiness',
93
+ title: 'No llms.txt file found',
94
+ description: 'llms.txt is a proposed standard for providing context to LLMs about your website. Having one helps AI systems better understand and represent your site.',
95
+ impact: 'AI systems may have less context about your site, potentially leading to less accurate representations.',
96
+ howToFix: 'Create an /llms.txt file with a Markdown description of your site. Include: site name, brief description, and links to key pages. See https://llmstxt.org/ for the specification.',
97
+ affectedUrls: [llmsTxtUrl],
98
+ details: {
99
+ specification: 'https://llmstxt.org/',
100
+ exampleFormat: `# Site Name
101
+
102
+ > Brief description of your site
103
+
104
+ ## About
105
+ - [About Us](/about): Learn more about our company
106
+
107
+ ## Products
108
+ - [Product A](/products/a): Description of product A
109
+ - [Product B](/products/b): Description of product B
110
+
111
+ ## Documentation
112
+ - [Docs](/docs): Full documentation`,
113
+ },
114
+ });
115
+ } else {
116
+ // Check structure quality
117
+ if (!structure.hasTitle) {
118
+ issues.push({
119
+ code: 'AI_LLMS_TXT_NO_TITLE',
120
+ severity: 'notice',
121
+ category: 'ai-readiness',
122
+ title: 'llms.txt missing title heading',
123
+ description: 'Your llms.txt file should start with a # heading containing your site/organization name.',
124
+ impact: 'LLMs may not properly identify your site.',
125
+ howToFix: 'Add a title heading at the top: # Your Site Name',
126
+ affectedUrls: [llmsTxtUrl],
127
+ });
128
+ }
129
+
130
+ if (!structure.hasDescription) {
131
+ issues.push({
132
+ code: 'AI_LLMS_TXT_NO_DESCRIPTION',
133
+ severity: 'notice',
134
+ category: 'ai-readiness',
135
+ title: 'llms.txt missing description',
136
+ description: 'Your llms.txt should include a brief description (blockquote starting with >) explaining what your site/organization does.',
137
+ impact: 'LLMs may not understand your site\'s purpose.',
138
+ howToFix: 'Add a description blockquote after the title: > Brief description of your site',
139
+ affectedUrls: [llmsTxtUrl],
140
+ });
141
+ }
142
+
143
+ if (!structure.hasLinks || structure.linkCount < 3) {
144
+ issues.push({
145
+ code: 'AI_LLMS_TXT_FEW_LINKS',
146
+ severity: 'notice',
147
+ category: 'ai-readiness',
148
+ title: 'llms.txt has few navigation links',
149
+ description: `Your llms.txt only has ${structure.linkCount} link(s). Include links to your most important pages to help LLMs navigate your content.`,
150
+ impact: 'LLMs may miss important content on your site.',
151
+ howToFix: 'Add more links in Markdown format: - [Page Title](/path): Brief description',
152
+ affectedUrls: [llmsTxtUrl],
153
+ });
154
+ }
155
+
156
+ if (contentLength < 200) {
157
+ issues.push({
158
+ code: 'AI_LLMS_TXT_TOO_SHORT',
159
+ severity: 'notice',
160
+ category: 'ai-readiness',
161
+ title: 'llms.txt content is very short',
162
+ description: `Your llms.txt is only ${contentLength} characters. Consider adding more context about your site.`,
163
+ impact: 'LLMs may not have enough context to properly represent your site.',
164
+ howToFix: 'Expand your llms.txt with more sections, descriptions, and links to key content.',
165
+ affectedUrls: [llmsTxtUrl],
166
+ });
167
+ }
168
+ }
169
+
170
+ return {
171
+ issues,
172
+ data: {
173
+ exists,
174
+ fullVersionExists,
175
+ content: content?.substring(0, 1000), // Truncate for data
176
+ structure,
177
+ contentLength,
178
+ },
179
+ };
180
+ }
181
+
182
+ function analyzeStructure(content: string): LlmsTxtData['structure'] {
183
+ const lines = content.split('\n');
184
+
185
+ let hasTitle = false;
186
+ let hasDescription = false;
187
+ let hasSections = false;
188
+ let hasLinks = false;
189
+ let linkCount = 0;
190
+
191
+ for (const line of lines) {
192
+ const trimmed = line.trim();
193
+
194
+ // Check for title (# heading at start)
195
+ if (trimmed.startsWith('# ') && !trimmed.startsWith('## ')) {
196
+ hasTitle = true;
197
+ }
198
+
199
+ // Check for description (blockquote)
200
+ if (trimmed.startsWith('>')) {
201
+ hasDescription = true;
202
+ }
203
+
204
+ // Check for sections (## headings)
205
+ if (trimmed.startsWith('## ')) {
206
+ hasSections = true;
207
+ }
208
+
209
+ // Check for Markdown links
210
+ const linkMatches = trimmed.match(/\[([^\]]+)\]\(([^)]+)\)/g);
211
+ if (linkMatches) {
212
+ hasLinks = true;
213
+ linkCount += linkMatches.length;
214
+ }
215
+ }
216
+
217
+ return {
218
+ hasTitle,
219
+ hasDescription,
220
+ hasSections,
221
+ hasLinks,
222
+ linkCount,
223
+ };
224
+ }
@@ -0,0 +1,296 @@
1
+ // Local SEO Checks
2
+ // Checks for LocalBusiness schema, NAP consistency, address/phone detection
3
+
4
+ import * as cheerio from 'cheerio';
5
+ import type { AuditIssue } from '../types.js';
6
+ import { ISSUE_DEFINITIONS } from '../types.js';
7
+
8
+ // Phone number patterns
9
+ const PHONE_PATTERNS = [
10
+ /\+?1?[-.\s]?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}/g, // US/Canada
11
+ /\+?[0-9]{1,3}[-.\s]?[0-9]{2,4}[-.\s]?[0-9]{3,4}[-.\s]?[0-9]{3,4}/g, // International
12
+ /\b[0-9]{3}[-.\s][0-9]{3}[-.\s][0-9]{4}\b/g, // Simple US format
13
+ ];
14
+
15
+ // Address patterns (simplified)
16
+ const ADDRESS_PATTERNS = [
17
+ /\d+\s+[\w\s]+(?:street|st|avenue|ave|road|rd|boulevard|blvd|drive|dr|lane|ln|way|court|ct|circle|cir|place|pl)[\s,]+[\w\s]+,?\s*(?:AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY)\s*\d{5}/gi,
18
+ /\d+\s+[\w\s]+,\s*[\w\s]+,\s*[A-Z]{2}\s*\d{5}/gi, // Generic US address
19
+ ];
20
+
21
+ export interface LocalSEOData {
22
+ hasLocalBusinessSchema: boolean;
23
+ hasOrganizationSchema: boolean;
24
+ detectedPhones: string[];
25
+ detectedAddresses: string[];
26
+ schemaData: {
27
+ name?: string;
28
+ address?: string;
29
+ phone?: string;
30
+ hours?: string[];
31
+ geo?: { lat: number; lng: number };
32
+ } | null;
33
+ socialProfiles: string[];
34
+ }
35
+
36
+ /**
37
+ * Extract and validate LocalBusiness/Organization schema
38
+ */
39
+ function extractSchema(html: string): {
40
+ hasLocalBusiness: boolean;
41
+ hasOrganization: boolean;
42
+ schemaData: LocalSEOData['schemaData'];
43
+ } {
44
+ const $ = cheerio.load(html);
45
+ let hasLocalBusiness = false;
46
+ let hasOrganization = false;
47
+ let schemaData: LocalSEOData['schemaData'] = null;
48
+
49
+ // Find JSON-LD scripts
50
+ $('script[type="application/ld+json"]').each((_, el) => {
51
+ try {
52
+ const content = $(el).html();
53
+ if (!content) return;
54
+
55
+ const jsonData = JSON.parse(content);
56
+ const schemas = Array.isArray(jsonData) ? jsonData : [jsonData];
57
+
58
+ for (const schema of schemas) {
59
+ // Handle @graph structure
60
+ const items = schema['@graph'] || [schema];
61
+
62
+ for (const item of items) {
63
+ const type = item['@type'];
64
+
65
+ // Check for LocalBusiness and its subtypes
66
+ const localBusinessTypes = [
67
+ 'LocalBusiness',
68
+ 'Restaurant',
69
+ 'Store',
70
+ 'MedicalBusiness',
71
+ 'FinancialService',
72
+ 'FoodEstablishment',
73
+ 'HealthAndBeautyBusiness',
74
+ 'HomeAndConstructionBusiness',
75
+ 'LegalService',
76
+ 'RealEstateAgent',
77
+ 'SportsActivityLocation',
78
+ ];
79
+
80
+ if (localBusinessTypes.some((t) => type === t || (Array.isArray(type) && type.includes(t)))) {
81
+ hasLocalBusiness = true;
82
+ schemaData = {
83
+ name: item.name,
84
+ address: formatAddress(item.address),
85
+ phone: item.telephone,
86
+ hours: item.openingHours,
87
+ geo: item.geo ? { lat: item.geo.latitude, lng: item.geo.longitude } : undefined,
88
+ };
89
+ }
90
+
91
+ if (type === 'Organization' || type === 'Corporation' || type === 'Person') {
92
+ hasOrganization = true;
93
+ if (!schemaData) {
94
+ schemaData = {
95
+ name: item.name,
96
+ address: formatAddress(item.address),
97
+ phone: item.telephone,
98
+ };
99
+ }
100
+ }
101
+ }
102
+ }
103
+ } catch {
104
+ // Invalid JSON-LD, skip
105
+ }
106
+ });
107
+
108
+ return { hasLocalBusiness, hasOrganization, schemaData };
109
+ }
110
+
111
+ /**
112
+ * Format address from schema
113
+ */
114
+ function formatAddress(address: unknown): string | undefined {
115
+ if (!address) return undefined;
116
+ if (typeof address === 'string') return address;
117
+ if (typeof address === 'object' && address !== null) {
118
+ const a = address as Record<string, string>;
119
+ return [a.streetAddress, a.addressLocality, a.addressRegion, a.postalCode, a.addressCountry].filter(Boolean).join(', ');
120
+ }
121
+ return undefined;
122
+ }
123
+
124
+ /**
125
+ * Detect phone numbers in page content
126
+ */
127
+ function detectPhones(html: string): string[] {
128
+ const $ = cheerio.load(html);
129
+ const text = $('body').text();
130
+ const phones = new Set<string>();
131
+
132
+ // Find tel: links
133
+ $('a[href^="tel:"]').each((_, el) => {
134
+ const href = $(el).attr('href');
135
+ if (href) {
136
+ phones.add(href.replace('tel:', '').trim());
137
+ }
138
+ });
139
+
140
+ // Find phone patterns in text
141
+ for (const pattern of PHONE_PATTERNS) {
142
+ const matches = text.match(pattern);
143
+ if (matches) {
144
+ matches.forEach((m) => phones.add(m.trim()));
145
+ }
146
+ }
147
+
148
+ // Filter out obviously invalid numbers
149
+ return Array.from(phones).filter((phone) => {
150
+ const digits = phone.replace(/\D/g, '');
151
+ return digits.length >= 10 && digits.length <= 15;
152
+ });
153
+ }
154
+
155
+ /**
156
+ * Detect addresses in page content
157
+ */
158
+ function detectAddresses(html: string): string[] {
159
+ const $ = cheerio.load(html);
160
+ const text = $('body').text();
161
+ const addresses = new Set<string>();
162
+
163
+ // Find address patterns
164
+ for (const pattern of ADDRESS_PATTERNS) {
165
+ const matches = text.match(pattern);
166
+ if (matches) {
167
+ matches.forEach((m) => addresses.add(m.trim()));
168
+ }
169
+ }
170
+
171
+ // Check for schema addresses
172
+ $('[itemprop="address"]').each((_, el) => {
173
+ const addr = $(el).text().trim();
174
+ if (addr) addresses.add(addr);
175
+ });
176
+
177
+ return Array.from(addresses);
178
+ }
179
+
180
+ /**
181
+ * Detect linked social profiles
182
+ */
183
+ function detectSocialProfiles(html: string): string[] {
184
+ const $ = cheerio.load(html);
185
+ const profiles: string[] = [];
186
+
187
+ const socialDomains = [
188
+ 'facebook.com',
189
+ 'twitter.com',
190
+ 'x.com',
191
+ 'linkedin.com',
192
+ 'instagram.com',
193
+ 'youtube.com',
194
+ 'tiktok.com',
195
+ 'pinterest.com',
196
+ 'github.com',
197
+ ];
198
+
199
+ $('a[href]').each((_, el) => {
200
+ const href = $(el).attr('href');
201
+ if (!href) return;
202
+
203
+ for (const domain of socialDomains) {
204
+ if (href.includes(domain)) {
205
+ // Normalize the URL
206
+ try {
207
+ const url = new URL(href);
208
+ if (!profiles.includes(url.href)) {
209
+ profiles.push(url.href);
210
+ }
211
+ } catch {
212
+ // Invalid URL, skip
213
+ }
214
+ break;
215
+ }
216
+ }
217
+ });
218
+
219
+ return profiles;
220
+ }
221
+
222
+ /**
223
+ * Analyze local SEO elements
224
+ */
225
+ export function analyzeLocalSEO(html: string, url: string): { issues: AuditIssue[]; data: LocalSEOData } {
226
+ const issues: AuditIssue[] = [];
227
+
228
+ // Extract schema
229
+ const { hasLocalBusiness, hasOrganization, schemaData } = extractSchema(html);
230
+
231
+ // Detect phones and addresses
232
+ const detectedPhones = detectPhones(html);
233
+ const detectedAddresses = detectAddresses(html);
234
+
235
+ // Detect social profiles
236
+ const socialProfiles = detectSocialProfiles(html);
237
+
238
+ // Generate issues
239
+ if (!hasLocalBusiness) {
240
+ issues.push({
241
+ ...ISSUE_DEFINITIONS.LOCAL_BUSINESS_SCHEMA_MISSING,
242
+ affectedUrls: [url],
243
+ });
244
+ }
245
+
246
+ if (!hasOrganization && !hasLocalBusiness) {
247
+ issues.push({
248
+ ...ISSUE_DEFINITIONS.ORGANIZATION_SCHEMA_MISSING,
249
+ affectedUrls: [url],
250
+ });
251
+ }
252
+
253
+ // Only flag missing address/phone for pages that appear to be business pages
254
+ const $ = cheerio.load(html);
255
+ const isBusinessPage =
256
+ $('a[href^="tel:"]').length > 0 ||
257
+ $('a[href^="mailto:"]').length > 0 ||
258
+ html.toLowerCase().includes('contact') ||
259
+ html.toLowerCase().includes('about us');
260
+
261
+ if (isBusinessPage) {
262
+ if (detectedAddresses.length === 0 && !schemaData?.address) {
263
+ issues.push({
264
+ ...ISSUE_DEFINITIONS.ADDRESS_NOT_DETECTED,
265
+ affectedUrls: [url],
266
+ });
267
+ }
268
+
269
+ if (detectedPhones.length === 0 && !schemaData?.phone) {
270
+ issues.push({
271
+ ...ISSUE_DEFINITIONS.PHONE_NOT_DETECTED,
272
+ affectedUrls: [url],
273
+ });
274
+ }
275
+ }
276
+
277
+ // Check for social profiles
278
+ if (socialProfiles.length === 0) {
279
+ issues.push({
280
+ ...ISSUE_DEFINITIONS.SOCIAL_PROFILES_NOT_LINKED,
281
+ affectedUrls: [url],
282
+ });
283
+ }
284
+
285
+ return {
286
+ issues,
287
+ data: {
288
+ hasLocalBusinessSchema: hasLocalBusiness,
289
+ hasOrganizationSchema: hasOrganization,
290
+ detectedPhones,
291
+ detectedAddresses,
292
+ schemaData,
293
+ socialProfiles,
294
+ },
295
+ };
296
+ }
@@ -0,0 +1,167 @@
1
+ import * as cheerio from 'cheerio';
2
+ import type { AuditIssue } from '../types.js';
3
+ import { ISSUE_DEFINITIONS } from '../types.js';
4
+
5
+ export interface MobileData {
6
+ hasViewport: boolean;
7
+ viewportContent?: string;
8
+ isResponsive: boolean;
9
+ tapTargetIssues: number;
10
+ fontSizeIssues: number;
11
+ }
12
+
13
+ export function analyzeMobile(html: string, url: string): { issues: AuditIssue[]; data: MobileData } {
14
+ const issues: AuditIssue[] = [];
15
+ const $ = cheerio.load(html);
16
+
17
+ // Check viewport meta tag
18
+ const viewportMeta = $('meta[name="viewport"]');
19
+ const hasViewport = viewportMeta.length > 0;
20
+ const viewportContent = viewportMeta.attr('content');
21
+
22
+ if (!hasViewport) {
23
+ issues.push({
24
+ ...ISSUE_DEFINITIONS.VIEWPORT_MISSING,
25
+ affectedUrls: [url],
26
+ });
27
+ } else if (viewportContent) {
28
+ // Check if viewport is responsive
29
+ const isResponsive = viewportContent.includes('width=device-width');
30
+
31
+ if (!isResponsive) {
32
+ // Check for fixed width
33
+ const widthMatch = viewportContent.match(/width=(\d+)/);
34
+ if (widthMatch) {
35
+ issues.push({
36
+ ...ISSUE_DEFINITIONS.VIEWPORT_NOT_RESPONSIVE,
37
+ affectedUrls: [url],
38
+ details: {
39
+ viewport: viewportContent,
40
+ fixedWidth: widthMatch[1],
41
+ },
42
+ });
43
+ }
44
+ }
45
+
46
+ // Check for user-scalable=no (bad for accessibility)
47
+ if (viewportContent.includes('user-scalable=no') || viewportContent.includes('user-scalable=0')) {
48
+ issues.push({
49
+ code: 'VIEWPORT_NO_ZOOM',
50
+ severity: 'warning',
51
+ category: 'mobile',
52
+ title: 'Viewport prevents zooming',
53
+ description: 'The viewport meta tag disables user scaling.',
54
+ impact: 'Users with visual impairments cannot zoom the page.',
55
+ howToFix: 'Remove user-scalable=no from the viewport meta tag.',
56
+ affectedUrls: [url],
57
+ });
58
+ }
59
+ }
60
+
61
+ // Check for tap target issues (basic heuristic)
62
+ // In a real implementation, this would analyze CSS computed styles
63
+ let tapTargetIssues = 0;
64
+ $('a, button, input, select, textarea').each((_, el) => {
65
+ const style = $(el).attr('style') || '';
66
+ // Basic check for very small explicit sizes
67
+ const heightMatch = style.match(/height:\s*(\d+)px/);
68
+ const widthMatch = style.match(/width:\s*(\d+)px/);
69
+
70
+ if (heightMatch && parseInt(heightMatch[1], 10) < 44) {
71
+ tapTargetIssues++;
72
+ }
73
+ if (widthMatch && parseInt(widthMatch[1], 10) < 44) {
74
+ tapTargetIssues++;
75
+ }
76
+ });
77
+
78
+ if (tapTargetIssues > 0) {
79
+ issues.push({
80
+ ...ISSUE_DEFINITIONS.TAP_TARGETS_TOO_SMALL,
81
+ affectedUrls: [url],
82
+ details: { count: tapTargetIssues },
83
+ });
84
+ }
85
+
86
+ // Check for font size issues (basic heuristic)
87
+ let fontSizeIssues = 0;
88
+ $('body *').each((_, el) => {
89
+ const style = $(el).attr('style') || '';
90
+ const fontSizeMatch = style.match(/font-size:\s*(\d+)px/);
91
+ if (fontSizeMatch && parseInt(fontSizeMatch[1], 10) < 12) {
92
+ fontSizeIssues++;
93
+ }
94
+ });
95
+
96
+ return {
97
+ issues,
98
+ data: {
99
+ hasViewport,
100
+ viewportContent,
101
+ isResponsive: hasViewport && (viewportContent?.includes('width=device-width') || false),
102
+ tapTargetIssues,
103
+ fontSizeIssues,
104
+ }
105
+ };
106
+ }
107
+
108
+ // Additional mobile-specific checks
109
+ export function checkMobileResources(html: string, url: string): AuditIssue[] {
110
+ const issues: AuditIssue[] = [];
111
+ const $ = cheerio.load(html);
112
+
113
+ // Check for Flash content (obsolete)
114
+ if ($('object[type*="flash"], embed[type*="flash"]').length > 0) {
115
+ issues.push({
116
+ code: 'FLASH_CONTENT',
117
+ severity: 'error',
118
+ category: 'mobile',
119
+ title: 'Flash content detected',
120
+ description: 'Page contains Flash content which is not supported on mobile devices.',
121
+ impact: 'Content is inaccessible on mobile devices and most modern browsers.',
122
+ howToFix: 'Replace Flash content with HTML5 alternatives.',
123
+ affectedUrls: [url],
124
+ });
125
+ }
126
+
127
+ // Check for plugins
128
+ if ($('object, embed, applet').length > 0) {
129
+ issues.push({
130
+ code: 'PLUGINS_DETECTED',
131
+ severity: 'notice',
132
+ category: 'mobile',
133
+ title: 'Plugins detected',
134
+ description: 'Page uses plugins which may not work on mobile devices.',
135
+ impact: 'Some content may not be accessible on mobile.',
136
+ howToFix: 'Consider replacing plugins with standard web technologies.',
137
+ affectedUrls: [url],
138
+ });
139
+ }
140
+
141
+ // Check for horizontal scroll (indication of non-responsive design)
142
+ // This is a heuristic based on fixed-width elements
143
+ let fixedWidthElements = 0;
144
+ $('*').each((_, el) => {
145
+ const style = $(el).attr('style') || '';
146
+ const widthMatch = style.match(/width:\s*(\d+)px/);
147
+ if (widthMatch && parseInt(widthMatch[1], 10) > 320) {
148
+ fixedWidthElements++;
149
+ }
150
+ });
151
+
152
+ if (fixedWidthElements > 5) {
153
+ issues.push({
154
+ code: 'POSSIBLE_HORIZONTAL_SCROLL',
155
+ severity: 'notice',
156
+ category: 'mobile',
157
+ title: 'Possible horizontal scrolling',
158
+ description: 'Multiple elements have fixed widths that may cause horizontal scrolling on mobile.',
159
+ impact: 'Poor mobile user experience.',
160
+ howToFix: 'Use responsive widths (percentages, max-width) instead of fixed pixel widths.',
161
+ affectedUrls: [url],
162
+ details: { count: fixedWidthElements },
163
+ });
164
+ }
165
+
166
+ return issues;
167
+ }