Skip to content

Commit 586e1bc

Browse files
committed
Support passing a custom date to post creator action
1 parent c1a1a70 commit 586e1bc

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/framework/src/Framework/Actions/CreatesNewMarkdownPostFile.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ class CreatesNewMarkdownPostFile
3737
* @param string|null $category The Primary Post Category.
3838
* @param string|null $author The Username of the Author.
3939
*/
40-
public function __construct(string $title, ?string $description, ?string $category, ?string $author, ?string $customContent = null)
40+
public function __construct(string $title, ?string $description, ?string $category, ?string $author, ?string $date = null, ?string $customContent = null)
4141
{
4242
$this->title = $title;
4343
$this->description = $description ?? 'A short description used in previews and SEO';
4444
$this->category = $category ?? 'blog';
4545
$this->author = $author ?? 'default';
4646
$this->customContent = $customContent;
4747

48-
$this->date = Carbon::now()->format('Y-m-d H:i');
48+
$this->date = $date ?? Carbon::now()->format('Y-m-d H:i');
4949
$this->identifier = Str::slug($title);
5050
}
5151

packages/framework/tests/Unit/CreatesNewMarkdownPostFileTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public function testWithDefaultData()
3939

4040
public function testWithCustomData()
4141
{
42-
$action = new CreatesNewMarkdownPostFile('foo', 'bar', 'baz', 'qux');
42+
$action = new CreatesNewMarkdownPostFile('foo', 'bar', 'baz', 'qux', '2024-06-01 12:20');
4343
$array = $action->toArray();
4444

4545
$this->assertSame([
4646
'title' => 'foo',
4747
'description' => 'bar',
4848
'category' => 'baz',
4949
'author' => 'qux',
50-
'date' => '2024-01-01 00:00',
50+
'date' => '2024-06-01 12:20',
5151
], $array);
5252
}
5353

@@ -76,7 +76,7 @@ public function testSave()
7676

7777
public function testSaveWithCustomContent()
7878
{
79-
$action = new CreatesNewMarkdownPostFile('Example Post', null, null, null, 'Hello World!');
79+
$action = new CreatesNewMarkdownPostFile('Example Post', null, null, null, null, 'Hello World!');
8080
$action->save();
8181

8282
$path = Hyde::path('_posts/example-post.md');

0 commit comments

Comments
 (0)