@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.
- package/dist/index.d.mts +77 -393
- package/dist/index.d.ts +77 -393
- package/dist/index.js +417 -6443
- package/dist/index.mjs +296 -6313
- package/package.json +6 -1
- package/scripts/build-deno.ts +0 -134
- package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
- package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
- package/src/analyzers/geo-analyzer.test.ts +0 -310
- package/src/analyzers/geo-analyzer.ts +0 -814
- package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
- package/src/analyzers/image-optimization-analyzer.ts +0 -348
- package/src/analyzers/index.ts +0 -233
- package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
- package/src/analyzers/internal-linking-analyzer.ts +0 -419
- package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
- package/src/analyzers/mobile-seo-analyzer.ts +0 -455
- package/src/analyzers/security-headers-analyzer.test.ts +0 -115
- package/src/analyzers/security-headers-analyzer.ts +0 -318
- package/src/analyzers/structured-data-analyzer.test.ts +0 -210
- package/src/analyzers/structured-data-analyzer.ts +0 -590
- package/src/audit/ai/analyzer.ts +0 -347
- package/src/audit/ai/index.ts +0 -29
- package/src/audit/ai/prompts/content-analysis.ts +0 -271
- package/src/audit/ai/types.ts +0 -179
- package/src/audit/checks/additional-checks.ts +0 -439
- package/src/audit/checks/ai-citation-worthiness.ts +0 -399
- package/src/audit/checks/ai-content-structure.ts +0 -325
- package/src/audit/checks/ai-readiness.ts +0 -339
- package/src/audit/checks/anchor-text.ts +0 -179
- package/src/audit/checks/answer-conciseness.ts +0 -322
- package/src/audit/checks/asset-minification.ts +0 -270
- package/src/audit/checks/bing-optimization.ts +0 -206
- package/src/audit/checks/brand-mention-optimization.ts +0 -349
- package/src/audit/checks/caching-headers.ts +0 -305
- package/src/audit/checks/canonical-advanced.ts +0 -150
- package/src/audit/checks/canonical-domain.ts +0 -196
- package/src/audit/checks/citation-quality.ts +0 -358
- package/src/audit/checks/client-rendering.ts +0 -542
- package/src/audit/checks/color-contrast.ts +0 -342
- package/src/audit/checks/content-freshness.ts +0 -170
- package/src/audit/checks/content-science.ts +0 -589
- package/src/audit/checks/conversion-elements.ts +0 -526
- package/src/audit/checks/crawlability.ts +0 -220
- package/src/audit/checks/directory-listing.ts +0 -172
- package/src/audit/checks/dom-analysis.ts +0 -191
- package/src/audit/checks/dom-size.ts +0 -246
- package/src/audit/checks/duplicate-content.ts +0 -194
- package/src/audit/checks/eeat-signals.ts +0 -990
- package/src/audit/checks/entity-seo.ts +0 -396
- package/src/audit/checks/featured-snippet.ts +0 -473
- package/src/audit/checks/freshness-signals.ts +0 -443
- package/src/audit/checks/funnel-intent.ts +0 -463
- package/src/audit/checks/hreflang.ts +0 -174
- package/src/audit/checks/html-compliance.ts +0 -302
- package/src/audit/checks/image-dimensions.ts +0 -167
- package/src/audit/checks/images.ts +0 -160
- package/src/audit/checks/indexnow.ts +0 -275
- package/src/audit/checks/interactive-tools.ts +0 -475
- package/src/audit/checks/internal-link-graph.ts +0 -436
- package/src/audit/checks/keyword-analysis.ts +0 -239
- package/src/audit/checks/keyword-cannibalization.ts +0 -385
- package/src/audit/checks/keyword-placement.ts +0 -471
- package/src/audit/checks/links.ts +0 -273
- package/src/audit/checks/llms-txt.ts +0 -224
- package/src/audit/checks/local-seo.ts +0 -296
- package/src/audit/checks/mobile.ts +0 -167
- package/src/audit/checks/modern-images.ts +0 -226
- package/src/audit/checks/navboost-signals.ts +0 -395
- package/src/audit/checks/on-page.ts +0 -209
- package/src/audit/checks/page-resources.ts +0 -285
- package/src/audit/checks/pagination.ts +0 -180
- package/src/audit/checks/performance.ts +0 -153
- package/src/audit/checks/platform-presence.ts +0 -580
- package/src/audit/checks/redirect-analysis.ts +0 -153
- package/src/audit/checks/redirect-chain.ts +0 -389
- package/src/audit/checks/resource-hints.ts +0 -420
- package/src/audit/checks/responsive-css.ts +0 -247
- package/src/audit/checks/responsive-images.ts +0 -396
- package/src/audit/checks/review-ecosystem.ts +0 -415
- package/src/audit/checks/robots-validation.ts +0 -373
- package/src/audit/checks/security-headers.ts +0 -188
- package/src/audit/checks/security.ts +0 -144
- package/src/audit/checks/serp-preview.ts +0 -251
- package/src/audit/checks/site-maturity.ts +0 -453
- package/src/audit/checks/social-meta.test.ts +0 -275
- package/src/audit/checks/social-meta.ts +0 -134
- package/src/audit/checks/soft-404.ts +0 -151
- package/src/audit/checks/structured-data.ts +0 -238
- package/src/audit/checks/tech-detection.ts +0 -496
- package/src/audit/checks/topical-clusters.ts +0 -435
- package/src/audit/checks/tracker-bloat.ts +0 -462
- package/src/audit/checks/tracking-verification.test.ts +0 -371
- package/src/audit/checks/tracking-verification.ts +0 -636
- package/src/audit/checks/url-safety.ts +0 -682
- package/src/audit/deno-entry.ts +0 -66
- package/src/audit/discovery/index.ts +0 -15
- package/src/audit/discovery/link-crawler.ts +0 -233
- package/src/audit/discovery/repo-routes.ts +0 -347
- package/src/audit/engine.ts +0 -627
- package/src/audit/fixes/index.ts +0 -209
- package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
- package/src/audit/fixes/social-meta-fixes.ts +0 -463
- package/src/audit/index.ts +0 -74
- package/src/audit/runner.test.ts +0 -299
- package/src/audit/runner.ts +0 -130
- package/src/audit/types.ts +0 -1963
- package/src/content/featured-snippet.ts +0 -367
- package/src/content/generator.test.ts +0 -534
- package/src/content/generator.ts +0 -501
- package/src/content/headline.ts +0 -317
- package/src/content/index.ts +0 -62
- package/src/content/intent.ts +0 -258
- package/src/content/keyword-density.ts +0 -349
- package/src/content/readability.ts +0 -262
- package/src/executor.ts +0 -336
- package/src/fixer/framework-fixes.test.ts +0 -489
- package/src/fixer/framework-fixes.ts +0 -5287
- package/src/fixer/index.ts +0 -6
- package/src/fixer/schemas.ts +0 -971
- package/src/fixer.ts +0 -642
- package/src/frameworks/detector.test.ts +0 -248
- package/src/frameworks/detector.ts +0 -899
- package/src/frameworks/index.ts +0 -68
- package/src/frameworks/recipes/angular.yaml +0 -171
- package/src/frameworks/recipes/astro.yaml +0 -206
- package/src/frameworks/recipes/django.yaml +0 -180
- package/src/frameworks/recipes/laravel.yaml +0 -137
- package/src/frameworks/recipes/nextjs.yaml +0 -268
- package/src/frameworks/recipes/nuxt.yaml +0 -175
- package/src/frameworks/recipes/rails.yaml +0 -188
- package/src/frameworks/recipes/react.yaml +0 -202
- package/src/frameworks/recipes/sveltekit.yaml +0 -154
- package/src/frameworks/recipes/vue.yaml +0 -137
- package/src/frameworks/recipes/wordpress.yaml +0 -209
- package/src/frameworks/suggestion-engine.ts +0 -357
- package/src/geo/geo-content.test.ts +0 -305
- package/src/geo/geo-content.ts +0 -266
- package/src/geo/geo-history.test.ts +0 -473
- package/src/geo/geo-history.ts +0 -433
- package/src/geo/geo-tracker.test.ts +0 -359
- package/src/geo/geo-tracker.ts +0 -411
- package/src/geo/index.ts +0 -11
- package/src/geo/llm-citation-checker.ts +0 -188
- package/src/git/commit-helper.test.ts +0 -261
- package/src/git/commit-helper.ts +0 -329
- package/src/git/index.ts +0 -12
- package/src/git/pr-helper.test.ts +0 -284
- package/src/git/pr-helper.ts +0 -307
- package/src/index.ts +0 -76
- package/src/keywords/ai-keyword-engine.ts +0 -1062
- package/src/keywords/ai-summarizer.ts +0 -387
- package/src/keywords/ci-mode.ts +0 -555
- package/src/keywords/engine.ts +0 -359
- package/src/keywords/index.ts +0 -151
- package/src/keywords/llm-judge.ts +0 -357
- package/src/keywords/nlp-analysis.ts +0 -706
- package/src/keywords/prioritizer.ts +0 -295
- package/src/keywords/site-crawler.ts +0 -342
- package/src/keywords/sources/autocomplete.ts +0 -139
- package/src/keywords/sources/competitive-search.ts +0 -450
- package/src/keywords/sources/competitor-analysis.ts +0 -374
- package/src/keywords/sources/dataforseo.ts +0 -206
- package/src/keywords/sources/free-sources.ts +0 -294
- package/src/keywords/sources/gsc.ts +0 -123
- package/src/keywords/topic-grouping.ts +0 -327
- package/src/keywords/types.ts +0 -144
- package/src/keywords/wizard.ts +0 -457
- package/src/loader.ts +0 -40
- package/src/ranking/index.ts +0 -5
- package/src/ranking/serp-client.ts +0 -348
- package/src/ranking/tracker.ts +0 -380
- package/src/ranking/types.ts +0 -123
- package/src/reports/index.ts +0 -7
- package/src/reports/report-generator.test.ts +0 -293
- package/src/reports/report-generator.ts +0 -713
- package/src/scheduler/alerts.test.ts +0 -458
- package/src/scheduler/alerts.ts +0 -328
- package/src/scheduler/index.ts +0 -8
- package/src/scheduler/scheduled-audit.test.ts +0 -377
- package/src/scheduler/scheduled-audit.ts +0 -149
- package/src/test/integration-test.ts +0 -325
- package/src/tools/analyzer.ts +0 -373
- package/src/tools/crawl.ts +0 -293
- package/src/tools/files.ts +0 -301
- package/src/tools/h1-fixer.ts +0 -249
- package/src/tools/index.ts +0 -67
- package/src/tracking/github-action.ts +0 -326
- package/src/tracking/google-analytics.ts +0 -265
- package/src/tracking/index.ts +0 -45
- package/src/tracking/report-generator.ts +0 -386
- package/src/tracking/search-console.ts +0 -335
- package/src/types.ts +0 -148
- package/src/utils/http.ts +0 -302
- package/src/wasm-adapter.ts +0 -297
- package/src/wasm-entry.ts +0 -14
- package/tsconfig.json +0 -17
- package/tsup.wasm.config.ts +0 -26
- package/vitest.config.ts +0 -15
|
@@ -1,296 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import * as cheerio from 'cheerio';
|
|
2
|
-
import type { AuditIssue } from '../types.js';
|
|
3
|
-
import { ISSUE_DEFINITIONS } from '../types.js';
|
|
4
|
-
|
|
5
|
-
export interface 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
|
-
}
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
// Modern Image Format Checks
|
|
2
|
-
// Checks for WebP/AVIF usage and image optimization
|
|
3
|
-
|
|
4
|
-
import * as cheerio from 'cheerio';
|
|
5
|
-
import type { AuditIssue } from '../types.js';
|
|
6
|
-
import { ISSUE_DEFINITIONS } from '../types.js';
|
|
7
|
-
|
|
8
|
-
// File extensions for modern formats
|
|
9
|
-
const MODERN_FORMATS = ['.webp', '.avif'];
|
|
10
|
-
const LEGACY_FORMATS = ['.jpg', '.jpeg', '.png', '.gif', '.bmp'];
|
|
11
|
-
|
|
12
|
-
export interface ImageInfo {
|
|
13
|
-
src: string;
|
|
14
|
-
alt: string | null;
|
|
15
|
-
width: number | null;
|
|
16
|
-
height: number | null;
|
|
17
|
-
loading: string | null;
|
|
18
|
-
format: string;
|
|
19
|
-
isModernFormat: boolean;
|
|
20
|
-
hasDimensions: boolean;
|
|
21
|
-
isLazyLoaded: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ModernImagesData {
|
|
25
|
-
totalImages: number;
|
|
26
|
-
modernFormatCount: number;
|
|
27
|
-
legacyFormatCount: number;
|
|
28
|
-
modernFormatPercentage: number;
|
|
29
|
-
images: ImageInfo[];
|
|
30
|
-
hasSourceSet: boolean;
|
|
31
|
-
hasPictureElements: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Extract format from URL
|
|
36
|
-
*/
|
|
37
|
-
function getImageFormat(url: string): string {
|
|
38
|
-
try {
|
|
39
|
-
const pathname = new URL(url, 'https://example.com').pathname.toLowerCase();
|
|
40
|
-
|
|
41
|
-
// Check for format in query string (common with CDNs)
|
|
42
|
-
const formatMatch = url.match(/[?&](?:format|f)=(\w+)/i);
|
|
43
|
-
if (formatMatch) {
|
|
44
|
-
return '.' + formatMatch[1].toLowerCase();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Check file extension
|
|
48
|
-
const extMatch = pathname.match(/\.([a-z0-9]+)$/i);
|
|
49
|
-
if (extMatch) {
|
|
50
|
-
return '.' + extMatch[1].toLowerCase();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return 'unknown';
|
|
54
|
-
} catch {
|
|
55
|
-
return 'unknown';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Check if format is modern
|
|
61
|
-
*/
|
|
62
|
-
function isModernFormat(format: string): boolean {
|
|
63
|
-
return MODERN_FORMATS.includes(format.toLowerCase());
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Extract image information from HTML
|
|
68
|
-
*/
|
|
69
|
-
function extractImages($: cheerio.CheerioAPI, baseUrl: string): ImageInfo[] {
|
|
70
|
-
const images: ImageInfo[] = [];
|
|
71
|
-
|
|
72
|
-
// Process img tags
|
|
73
|
-
$('img').each((_, el) => {
|
|
74
|
-
const src = $(el).attr('src') || $(el).attr('data-src') || '';
|
|
75
|
-
const srcset = $(el).attr('srcset') || '';
|
|
76
|
-
const alt = $(el).attr('alt') || null;
|
|
77
|
-
const width = $(el).attr('width') ? parseInt($(el).attr('width')!, 10) : null;
|
|
78
|
-
const height = $(el).attr('height') ? parseInt($(el).attr('height')!, 10) : null;
|
|
79
|
-
const loading = $(el).attr('loading') || null;
|
|
80
|
-
|
|
81
|
-
// Skip data URIs and empty sources
|
|
82
|
-
if (!src || src.startsWith('data:')) return;
|
|
83
|
-
|
|
84
|
-
// Resolve relative URLs
|
|
85
|
-
let fullSrc = src;
|
|
86
|
-
try {
|
|
87
|
-
fullSrc = new URL(src, baseUrl).href;
|
|
88
|
-
} catch {
|
|
89
|
-
// Keep original if URL parsing fails
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const format = getImageFormat(fullSrc);
|
|
93
|
-
|
|
94
|
-
images.push({
|
|
95
|
-
src: fullSrc,
|
|
96
|
-
alt,
|
|
97
|
-
width,
|
|
98
|
-
height,
|
|
99
|
-
loading,
|
|
100
|
-
format,
|
|
101
|
-
isModernFormat: isModernFormat(format),
|
|
102
|
-
hasDimensions: width !== null && height !== null,
|
|
103
|
-
isLazyLoaded: loading === 'lazy' || $(el).attr('data-src') !== undefined,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// Check srcset for modern formats
|
|
107
|
-
if (srcset) {
|
|
108
|
-
const srcsetUrls = srcset.split(',').map((s) => s.trim().split(' ')[0]);
|
|
109
|
-
for (const srcsetUrl of srcsetUrls) {
|
|
110
|
-
const srcsetFormat = getImageFormat(srcsetUrl);
|
|
111
|
-
if (isModernFormat(srcsetFormat) && !images.some((img) => img.src === srcsetUrl)) {
|
|
112
|
-
images.push({
|
|
113
|
-
src: srcsetUrl,
|
|
114
|
-
alt,
|
|
115
|
-
width: null,
|
|
116
|
-
height: null,
|
|
117
|
-
loading,
|
|
118
|
-
format: srcsetFormat,
|
|
119
|
-
isModernFormat: true,
|
|
120
|
-
hasDimensions: false,
|
|
121
|
-
isLazyLoaded: loading === 'lazy',
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// Check picture elements for modern format sources
|
|
129
|
-
$('picture source').each((_, el) => {
|
|
130
|
-
const srcset = $(el).attr('srcset') || '';
|
|
131
|
-
const type = $(el).attr('type') || '';
|
|
132
|
-
|
|
133
|
-
if (type.includes('webp') || type.includes('avif')) {
|
|
134
|
-
const srcsetUrls = srcset.split(',').map((s) => s.trim().split(' ')[0]);
|
|
135
|
-
for (const srcsetUrl of srcsetUrls) {
|
|
136
|
-
if (!images.some((img) => img.src === srcsetUrl)) {
|
|
137
|
-
images.push({
|
|
138
|
-
src: srcsetUrl,
|
|
139
|
-
alt: null,
|
|
140
|
-
width: null,
|
|
141
|
-
height: null,
|
|
142
|
-
loading: null,
|
|
143
|
-
format: type.includes('webp') ? '.webp' : '.avif',
|
|
144
|
-
isModernFormat: true,
|
|
145
|
-
hasDimensions: false,
|
|
146
|
-
isLazyLoaded: false,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return images;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Analyze image formats and optimization
|
|
158
|
-
*/
|
|
159
|
-
export function analyzeModernImages(html: string, url: string): { issues: AuditIssue[]; data: ModernImagesData } {
|
|
160
|
-
const issues: AuditIssue[] = [];
|
|
161
|
-
const $ = cheerio.load(html);
|
|
162
|
-
|
|
163
|
-
// Extract images
|
|
164
|
-
const images = extractImages($, url);
|
|
165
|
-
|
|
166
|
-
// Filter to unique images by src
|
|
167
|
-
const uniqueImages = images.filter((img, idx, arr) => arr.findIndex((i) => i.src === img.src) === idx);
|
|
168
|
-
|
|
169
|
-
// Count formats
|
|
170
|
-
const modernFormatCount = uniqueImages.filter((img) => img.isModernFormat).length;
|
|
171
|
-
const legacyFormatCount = uniqueImages.filter(
|
|
172
|
-
(img) => !img.isModernFormat && LEGACY_FORMATS.includes(img.format)
|
|
173
|
-
).length;
|
|
174
|
-
|
|
175
|
-
// Check for picture elements and srcset
|
|
176
|
-
const hasPictureElements = $('picture').length > 0;
|
|
177
|
-
const hasSourceSet = $('img[srcset]').length > 0 || $('picture source[srcset]').length > 0;
|
|
178
|
-
|
|
179
|
-
// Calculate percentage
|
|
180
|
-
const totalRelevantImages = modernFormatCount + legacyFormatCount;
|
|
181
|
-
const modernFormatPercentage = totalRelevantImages > 0 ? Math.round((modernFormatCount / totalRelevantImages) * 100) : 100;
|
|
182
|
-
|
|
183
|
-
// Generate issues
|
|
184
|
-
if (legacyFormatCount > 0 && !hasPictureElements && !hasSourceSet) {
|
|
185
|
-
const legacyImages = uniqueImages.filter((img) => !img.isModernFormat && LEGACY_FORMATS.includes(img.format));
|
|
186
|
-
|
|
187
|
-
issues.push({
|
|
188
|
-
...ISSUE_DEFINITIONS.IMAGE_NOT_WEBP_AVIF,
|
|
189
|
-
affectedUrls: legacyImages.slice(0, 10).map((img) => img.src),
|
|
190
|
-
details: {
|
|
191
|
-
legacyImageCount: legacyFormatCount,
|
|
192
|
-
modernImageCount: modernFormatCount,
|
|
193
|
-
modernFormatPercentage,
|
|
194
|
-
recommendation: 'Convert images to WebP or AVIF format for 25-50% smaller file sizes',
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Check for images without dimensions (causes CLS)
|
|
200
|
-
const imagesWithoutDimensions = uniqueImages.filter(
|
|
201
|
-
(img) => !img.hasDimensions && !img.isLazyLoaded && LEGACY_FORMATS.includes(img.format)
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
if (imagesWithoutDimensions.length > 0) {
|
|
205
|
-
issues.push({
|
|
206
|
-
...ISSUE_DEFINITIONS.IMG_NO_DIMENSIONS,
|
|
207
|
-
affectedUrls: imagesWithoutDimensions.slice(0, 10).map((img) => img.src),
|
|
208
|
-
details: {
|
|
209
|
-
count: imagesWithoutDimensions.length,
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return {
|
|
215
|
-
issues,
|
|
216
|
-
data: {
|
|
217
|
-
totalImages: uniqueImages.length,
|
|
218
|
-
modernFormatCount,
|
|
219
|
-
legacyFormatCount,
|
|
220
|
-
modernFormatPercentage,
|
|
221
|
-
images: uniqueImages,
|
|
222
|
-
hasSourceSet,
|
|
223
|
-
hasPictureElements,
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
}
|