42 lines
997 B
PHP
42 lines
997 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Console\Commands\Markdown;
|
||
|
|
||
|
use App\Services\Markdown\Linter;
|
||
|
use Illuminate\Console\Command;
|
||
|
use Illuminate\Support\Facades\Log;
|
||
|
use Illuminate\Support\Facades\Storage;
|
||
|
|
||
|
class Lint extends Command
|
||
|
{
|
||
|
/**
|
||
|
* The name and signature of the console command.
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $signature = 'markdown:lint { path : Path to the file to be formatted }';
|
||
|
|
||
|
/**
|
||
|
* The console command description.
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $description = 'Format markdown';
|
||
|
|
||
|
/**
|
||
|
* Execute the console command.
|
||
|
*/
|
||
|
public function handle()
|
||
|
{
|
||
|
Log::debug(sprintf('Linting %s', $this->argument('path')));
|
||
|
|
||
|
$content = Storage::disk(env('CONTENT_DISK'))->get($this->argument('path'));
|
||
|
$lint = new Linter($content);
|
||
|
$result = $lint->format();
|
||
|
|
||
|
if ($result !== $content) {
|
||
|
Storage::disk(env('CONTENT_DISK'))->put($this->argument('path'), $result);
|
||
|
}
|
||
|
}
|
||
|
}
|