UNPKG

@casoon/auditmysite

Version:

Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe

116 lines • 5.08 kB
"use strict"; /** * Smart URL Sampler - Adaptive URL Selection * * This module implements intelligent URL sampling that: * 1. Tests URLs sequentially from the sitemap * 2. Skips URLs that redirect (301, 302) * 3. Continues until the desired number of GOOD pages is found * 4. Handles 404s and other errors appropriately * 5. Provides progress feedback */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SmartUrlSampler = void 0; class SmartUrlSampler { constructor(checker, options) { this.checker = checker; this.options = { maxAttempts: options.maxPages * 3, // Try 3x more URLs to find good ones timeout: 10000, verbose: false, skipRedirects: true, skip404s: true, ...options }; } /** * Sample URLs from a sitemap to find the desired number of good pages */ async sampleGoodUrls(allUrls) { const startTime = Date.now(); const result = { goodUrls: [], skippedUrls: [], errorUrls: [], totalAttempts: 0, samplingTime: 0 }; if (this.options.verbose) { console.log(`šŸŽÆ Smart URL Sampling: Finding ${this.options.maxPages} good pages from ${allUrls.length} URLs`); } // Ensure we don't try more URLs than available or than maxAttempts const maxToTry = Math.min(allUrls.length, this.options.maxAttempts || allUrls.length); for (let i = 0; i < maxToTry && result.goodUrls.length < this.options.maxPages; i++) { const url = allUrls[i]; result.totalAttempts++; if (this.options.verbose) { console.log(`šŸ” Testing URL ${i + 1}/${maxToTry}: ${url}`); } try { // Test the URL with minimal analysis (just check if it's accessible) const testResult = await this.testUrlAccessibility(url); // Check the result and categorize if (testResult.skipped && this.options.skipRedirects) { if (this.options.verbose) { console.log(` ā†Ŗļø Skipped (redirect): ${testResult.redirectInfo?.finalUrl || 'unknown'}`); } result.skippedUrls.push(url); } else if (testResult.errors.some(e => e.includes('404')) && this.options.skip404s) { if (this.options.verbose) { console.log(` āŒ Skipped (404): Not found`); } result.skippedUrls.push(url); } else if (testResult.crashed) { if (this.options.verbose) { console.log(` šŸ’„ Error (technical): ${testResult.errors[0] || 'Unknown error'}`); } result.errorUrls.push(url); } else { // This is a good URL! if (this.options.verbose) { console.log(` āœ… Good URL (${result.goodUrls.length + 1}/${this.options.maxPages})`); } result.goodUrls.push(url); } } catch (error) { if (this.options.verbose) { console.log(` šŸ’„ Error testing URL: ${error}`); } result.errorUrls.push(url); } } result.samplingTime = Date.now() - startTime; if (this.options.verbose) { console.log(`\nšŸ“Š Sampling Results:`); console.log(` āœ… Good URLs found: ${result.goodUrls.length}/${this.options.maxPages}`); console.log(` ā†Ŗļø Skipped URLs: ${result.skippedUrls.length}`); console.log(` āŒ Error URLs: ${result.errorUrls.length}`); console.log(` šŸ• Sampling time: ${Math.round(result.samplingTime / 1000)}s`); } return result; } /** * Test a single URL to determine if it's accessible (not redirected, not 404) * MINIMAL CHECK: Only test HTTP status, skip all comprehensive analysis */ async testUrlAccessibility(url) { // šŸŽÆ Use the new minimal test method - NO COMPREHENSIVE ANALYSIS // This avoids mobile-friendliness, performance, SEO analysis during sampling return await this.checker.testUrlMinimal(url, this.options.timeout || 5000); } /** * Get summary statistics from sampling result */ static getSummary(result) { const total = result.totalAttempts; const goodRate = total > 0 ? (result.goodUrls.length / total * 100).toFixed(1) : '0'; const skipRate = total > 0 ? (result.skippedUrls.length / total * 100).toFixed(1) : '0'; return `Found ${result.goodUrls.length} good URLs from ${total} tested (${goodRate}% success, ${skipRate}% skipped)`; } } exports.SmartUrlSampler = SmartUrlSampler; //# sourceMappingURL=smart-url-sampler.js.map