diff --git a/composer.json b/composer.json index 1b54998..bf03932 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "illuminate/contracts": "^9.0|^10.0|^11.0", "j0k3r/php-readability": "^2.0", "jeremykendall/php-domain-parser": "^6.3", + "laravel/prompts": "^0.3.2", "spatie/browsershot": "^3.0|^4.0|^5.0", "spatie/laravel-package-tools": "^1.13", "symfony/dom-crawler": "^6.2|^7.0", diff --git a/src/Commands/SeoScanUrl.php b/src/Commands/SeoScanUrl.php index 0a2ebd2..01c0e2b 100644 --- a/src/Commands/SeoScanUrl.php +++ b/src/Commands/SeoScanUrl.php @@ -5,28 +5,53 @@ use Illuminate\Console\Command; use Vormkracht10\Seo\Facades\Seo; +use function Laravel\Prompts\progress; +use function Laravel\Prompts\text; +use function Laravel\Prompts\confirm; + class SeoScanUrl extends Command { - public $signature = 'seo:scan-url {url} {--javascript}'; + public $signature = 'seo:scan-url {url?} {--javascript}'; public $description = 'Scan the SEO score of a url'; public function handle(): int { - $this->info('Please wait while we scan your web page...'); - $this->line(''); + $url = $this->argument('url') ?? text( + label: 'Pleaes enter the url', + validate: function (string $value) { + try { + if (!\Illuminate\Support\Facades\Http::get($value)->successful()) { + return 'Please enter a valid url.'; + } - $progress = $this->output->createProgressBar(getCheckCount()); + return null; + } catch (\Exception $e) { + return 'Please enter a valid url.'; + } + } + ); + + $useJavascript = $this->option('javascript') ? + $this->option('javascript') : + confirm( + label: 'Do you want to use JavaScript?', + default: true, + yes: 'I do', + no: 'I dont' + ); + + $progress = progress(label: 'Please wait while we scan your web page...', steps: getCheckCount(), hint: $url); $progress->start(); - $score = Seo::check($this->argument('url'), $progress, $this->option('javascript')); + $score = Seo::check($url, $progress, $useJavascript); $progress->finish(); $this->line(''); $this->line(''); $this->line('-----------------------------------------------------------------------------------------------------------------------------------'); - $this->line('> '.$this->argument('url').' | '.$score->getSuccessfulChecks()->count().' passed '.($score->getFailedChecks()->count().' failed')); + $this->line('> ' . $url . ' | ' . $score->getSuccessfulChecks()->count() . ' passed ' . ($score->getFailedChecks()->count() . ' failed')); $this->line('-----------------------------------------------------------------------------------------------------------------------------------'); $this->line(''); diff --git a/src/Seo.php b/src/Seo.php index caa8b17..aba2149 100755 --- a/src/Seo.php +++ b/src/Seo.php @@ -8,6 +8,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; +use Laravel\Prompts\Progress; use Spatie\Browsershot\Browsershot; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\DomCrawler\Crawler; @@ -16,9 +17,9 @@ class Seo { /** - * @var ProgressBar|null The progress bar to use for the checks. + * @var Progress|null The progress bar to use for the checks. */ - public ?ProgressBar $progress; + public ?Progress $progress; public string $url; @@ -28,7 +29,7 @@ public function __construct( protected Collection $failed, ) {} - public function check(string $url, ?ProgressBar $progress = null, bool $useJavascript = false): SeoScore + public function check(string $url, ?Progress $progress = null, bool $useJavascript = false): SeoScore { $this->progress = $progress; $this->url = $url;