-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNewPost.php
61 lines (45 loc) · 1.47 KB
/
NewPost.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Swiftmade\Blogdown\Commands;
use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Artisan;
class NewPost extends Command
{
protected $signature = 'blog:new';
protected $description = 'Creates a new post';
public function handle()
{
$title = $this->ask('Title of your new post');
$author = $this->askWithCompletion('Author', array_keys(
config('blogdown.authors')
));
$meta = [
'title' => $title,
'author' => $author,
'date' => date(config('blogdown.date_format')),
'summary' => 'Summary of your post...',
'tags' => 'tag1, tag2',
'draft' => true,
];
$folder = resource_path('views/' . config('blogdown.blog_folder'));
File::ensureDirectoryExists($folder);
$file = Str::slug($title) . '.md.blade.php';
file_put_contents(
$folder . '/' . $file,
$this->getMetaAsText($meta)
);
$this->info('New post created: "' . $title . '"');
$this->comment('Path: ' . $folder . '/' . $file);
Artisan::call('blog:index');
}
private function getMetaAsText(array $data)
{
$meta = '{{--' . PHP_EOL;
foreach ($data as $key => $value) {
$meta .= $key . ': ' . $value . PHP_EOL;
}
$meta .= '--}}' . PHP_EOL;
return $meta;
}
}