Skip to content

Commit

Permalink
No longer automatically create the data collections directory
Browse files Browse the repository at this point in the history
Fixes #1735
  • Loading branch information
caendesilva committed Jun 23, 2024
1 parent b3807fb commit 22c4b66
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 39 deletions.
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This serves two purposes:
- Changed how the documentation search is generated, to be an `InMemoryPage` instead of a post-build task.
- Media asset files are now copied using the new build task instead of the deprecated `BuildService::transferMediaAssets()` method.
- Calling the `Include::path()` method will no longer create the includes directory in https://github.com/hydephp/develop/pull/1707

- Calling the `DataCollections` methods will no longer create the data collections directory in https://github.com/hydephp/develop/pull/1732

### Deprecated
- for soon-to-be removed features.
Expand Down Expand Up @@ -223,3 +223,5 @@ For example, if you triggered the media transfer with a build service method cal
The DataCollections feature has been reworked to improve the developer experience and make it more consistent with the rest of the API.

Unfortunately, this means that existing setups may need to be adjusted to work with the new API.

- Calling the `DataCollections` methods will no longer create the data collections directory automatically
1 change: 0 additions & 1 deletion docs/digging-deeper/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Follow these conventions and creating dynamic static sites will be a breeze.
6. While not enforced, each subdirectory should probably only have the same filetype to prevent developer confusion.
7. Unlike source files for pages, files starting with underscores are not ignored.
8. You can customize the source directory for collections through a service provider.
9. If the base source directory does not exist, it will be created for you.


## Available Collection Types
Expand Down
9 changes: 0 additions & 9 deletions packages/framework/src/Support/DataCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Yaml\Yaml;
use Hyde\Markdown\Models\FrontMatter;
use Hyde\Framework\Actions\MarkdownFileParser;
use Hyde\Framework\Concerns\InteractsWithDirectories;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

Expand All @@ -35,8 +34,6 @@
*/
class DataCollections extends Collection
{
use InteractsWithDirectories;

/**
* The base directory for all data collections. Can be modified using a service provider.
*/
Expand All @@ -51,8 +48,6 @@ class DataCollections extends Collection
*/
public static function markdown(string $name): static
{
static::needsDirectory(static::$sourceDirectory);

return new static(static::findFiles($name, 'md')->mapWithKeys(function (string $file): array {
return [static::makeIdentifier($file) => MarkdownFileParser::parse($file)];
}));
Expand All @@ -67,8 +62,6 @@ public static function markdown(string $name): static
*/
public static function yaml(string $name): static
{
static::needsDirectory(static::$sourceDirectory);

return new static(static::findFiles($name, ['yaml', 'yml'])->mapWithKeys(function (string $file): array {
$content = Filesystem::get($file);
$content = Str::between($content, '---', '---');
Expand All @@ -89,8 +82,6 @@ public static function yaml(string $name): static
*/
public static function json(string $name, bool $asArray = false): static
{
static::needsDirectory(static::$sourceDirectory);

return new static(static::findFiles($name, 'json')->mapWithKeys(function (string $file) use ($asArray): array {
return [static::makeIdentifier($file) => json_decode(Filesystem::get($file), $asArray)];
}));
Expand Down
28 changes: 0 additions & 28 deletions packages/framework/tests/Feature/DataCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

namespace Hyde\Framework\Testing\Feature;

use Hyde\Hyde;
use Hyde\Markdown\Models\FrontMatter;
use Hyde\Markdown\Models\MarkdownDocument;
use Hyde\Support\DataCollections;
use Hyde\Testing\TestCase;
use Illuminate\Support\Facades\File;

/**
* @covers \Hyde\Support\DataCollections
Expand Down Expand Up @@ -170,30 +168,4 @@ public function testSourceDirectoryCanBeChanged()

DataCollections::$sourceDirectory = 'resources/collections';
}

public function testSourceDirectoryIsAutomaticallyAddedIfMissing()
{
$this->directory('resources/collections');
File::deleteDirectory(Hyde::path('resources/collections'));
$this->assertDirectoryDoesNotExist(Hyde::path('resources/collections'));

DataCollections::markdown('foo');

$this->assertDirectoryExists(Hyde::path('resources/collections'));
}

public function testCustomSourceDirectoryIsAutomaticallyAddedIfMissing()
{
$this->directory('foo');
File::deleteDirectory(Hyde::path('foo'));

$this->assertDirectoryDoesNotExist(Hyde::path('foo'));

DataCollections::$sourceDirectory = 'foo';
DataCollections::markdown('bar');

$this->assertDirectoryExists(Hyde::path('foo'));

DataCollections::$sourceDirectory = 'resources/collections';
}
}

0 comments on commit 22c4b66

Please sign in to comment.