generated from ohseesoftware/laravel-package-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add make:article command to generate a new article
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace OhSeeSoftware\LaravelMarkdownContent\Console\Commands; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
use Illuminate\Support\Str; | ||
|
||
class MakeArticleCommand extends GeneratorCommand | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'make:article {type} {slug}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Scaffolds out a new article.'; | ||
|
||
protected function getStub() | ||
{ | ||
return realpath(__DIR__ . '/../../stubs/article.stub'); | ||
} | ||
|
||
public function handle() | ||
{ | ||
$slug = trim($this->argument('slug')); | ||
$type = trim($this->argument('type')); | ||
|
||
$path = base_path("content/articles/{$slug}.md"); | ||
|
||
if ($this->files->exists($path)) { | ||
$this->error("{$slug} already exists!"); | ||
|
||
return false; | ||
} | ||
|
||
$stub = $this->files->get($this->getStub()); | ||
$stub = Str::of($stub) | ||
->replace("\nslug:", "\nslug: {$slug}") | ||
->replace("\ntype:", "\ntype: {$type}") | ||
->replace('title:', "title: '".Str::of($slug)->title()->replace('-', ' ')."'") | ||
->replace('updated_at:', 'updated_at: '.now()->format('Y-m-d')) | ||
->replace('created_at:', 'created_at: '.now()->format('Y-m-d')); | ||
|
||
$this->files->put($path, $stub); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
slug: | ||
type: | ||
title: | ||
category_slug: | ||
excerpt: | ||
updated_at: | ||
created_at: | ||
--- |