Skip to content

Commit

Permalink
Add Laravel Prompts to SeoScanUrl Command
Browse files Browse the repository at this point in the history
  • Loading branch information
arduinomaster22 committed Jan 9, 2025
1 parent 022b5bd commit 2f26ea9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 31 additions & 6 deletions src/Commands/SeoScanUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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').' | <fg=green>'.$score->getSuccessfulChecks()->count().' passed</> <fg=red>'.($score->getFailedChecks()->count().' failed</>'));
$this->line('> ' . $url . ' | <fg=green>' . $score->getSuccessfulChecks()->count() . ' passed</> <fg=red>' . ($score->getFailedChecks()->count() . ' failed</>'));
$this->line('-----------------------------------------------------------------------------------------------------------------------------------');
$this->line('');

Expand Down
7 changes: 4 additions & 3 deletions src/Seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 2f26ea9

Please sign in to comment.