Skip to content

Add Laravel Prompts to command interface #19 #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\confirm;
use function Laravel\Prompts\progress;
use function Laravel\Prompts\text;

class SeoScanUrl extends Command
{
public $signature = 'seo:scan-url {url} {--javascript}';
public $signature = 'seo:scan-url {url?} {--javascript}';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I don't want to enter a url and want to scan the whole website?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah never mind I see it's the Scan URL command 🙂


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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo here

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
8 changes: 4 additions & 4 deletions src/Seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
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;
use Symfony\Component\Finder\Finder;

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 +28,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
Loading