From 453608939e0a76cef67b173d3db52ee672274d9b Mon Sep 17 00:00:00 2001 From: Keith Damiani Date: Tue, 5 Jan 2021 21:38:52 +0100 Subject: [PATCH] Use string key as remote collection item temp filename, if present --- src/Collection/CollectionRemoteItem.php | 10 +++++--- tests/RemoteCollectionsTest.php | 31 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Collection/CollectionRemoteItem.php b/src/Collection/CollectionRemoteItem.php index 0d33d58c..c4eb3b6a 100644 --- a/src/Collection/CollectionRemoteItem.php +++ b/src/Collection/CollectionRemoteItem.php @@ -9,13 +9,13 @@ class CollectionRemoteItem { private $item; private $index; - private $prefix; + private $collectionName; public function __construct($item, $index = 0, $collectionName = null) { $this->item = $item; $this->index = $index; - $this->prefix = $collectionName . '_'; + $this->collectionName = $collectionName; } public function getContent() @@ -27,7 +27,11 @@ public function getContent() public function getFilename() { - return Arr::get($this->item, 'filename', $this->prefix . ($this->index + 1)) . '.blade.md'; + $default = is_int($this->index) + ? $this->collectionName . '-' . ($this->index + 1) + : $this->index; + + return Arr::get($this->item, 'filename', $default) . '.blade.md'; } protected function getHeader() diff --git a/tests/RemoteCollectionsTest.php b/tests/RemoteCollectionsTest.php index 2b985218..c7e4eff5 100644 --- a/tests/RemoteCollectionsTest.php +++ b/tests/RemoteCollectionsTest.php @@ -439,6 +439,37 @@ public function filename_for_output_file_is_set_to_collection_name_plus_index_if $this->assertTrue($files->hasChild('build/test/test-2.html')); } + /** + * @test + */ + public function filename_for_output_file_is_set_to_collection_name_plus_array_key_if_filename_not_specified_and_key_is_string() + { + $config = collect([ + 'collections' => [ + 'test' => [ + 'extends' => '_layouts.master', + 'items' => [ + 'foo' => [ + 'content' => 'item 1', + ], + 'bar' => [ + 'content' => 'item 2', + ], + ], + ], + ], + ]); + $files = $this->setupSource([ + '_layouts' => [ + 'master.blade.php' => "
@yield('content')
", + ], + ]); + $this->buildSite($files, $config); + + $this->assertTrue($files->hasChild('build/test/foo.html')); + $this->assertTrue($files->hasChild('build/test/bar.html')); + } + /** * @test */