Skip to content

Commit 511c7bd

Browse files
authored
Merge pull request #879 from hydephp/datacollections-package-updates
Breaking: Change default DataCollection directory from `_data` to `resources/collections`
2 parents 18e9111 + a757943 commit 511c7bd

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

docs/digging-deeper/collections.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ You may need to enable the module by adding the feature to your Hyde configurati
3535

3636
To make collections easy to use and understand, Hyde makes a few assumptions about the structure of your collections. Follow these conventions and creating dynamic static sites will be a breeze.
3737

38-
1. Collections are stored in the new `_data` directory.
38+
1. Collections are stored in the new `resources/collections` directory.
3939
2. Each subdirectory in here can be a collection.
4040
3. Data collections are automatically generated when you use the Facade you will learn about below.
4141
4. When using one of the facades, you need to specify the collection name, this name is the name of the subdirectory.
4242
5. Each subdirectory should probably only have the same filetype to prevent developer confusion, but this is not enforced.
4343
6. Unlike Markdown pages, files starting with underscores are not ignored.
44-
7. You can customize the base `_data` directory through a service provider.
44+
7. You can customize the base `resources/collections` directory through a service provider.
4545

4646

4747
### Markdown Collections - Hands on Guide
@@ -57,7 +57,7 @@ In it we will place Markdown files. Each file will be a testimonial. The Markdow
5757
Here is the sample Markdown we will use:
5858

5959
```blade
60-
// filepath: _data/testimonials/1.md
60+
// filepath: resources/collections/testimonials/1.md
6161
---
6262
author: John Doe
6363
---
@@ -68,7 +68,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit...
6868
Let's take a look at our directory structure. I just copied the same file a few times. You can name the files anything you want, I kept it simple and just numbered them.
6969

7070
```tree
71-
_data
71+
resources/collections
7272
└── testimonials
7373
├── 1.md
7474
├── 2.md

packages/framework/src/Framework/Features/DataCollections/DataCollection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DataCollection extends Collection
1818
{
1919
public string $key;
2020

21-
public static string $sourceDirectory = '_data';
21+
public static string $sourceDirectory = 'resources/collections';
2222

2323
public function __construct(string $key)
2424
{
@@ -40,10 +40,10 @@ public function getMarkdownFiles(): array
4040
}
4141

4242
/**
43-
* Get a collection of Markdown documents in the _data/<$key> directory.
43+
* Get a collection of Markdown documents in the resources/collections/<$key> directory.
4444
* Each Markdown file will be parsed into a MarkdownDocument with front matter.
4545
*
46-
* @param string $key for a subdirectory of the _data directory
46+
* @param string $key for a subdirectory of the resources/collections directory
4747
* @return DataCollection<\Hyde\Markdown\Models\MarkdownDocument>
4848
*/
4949
public static function markdown(string $key): static

packages/framework/src/Framework/Features/DataCollections/DataCollectionServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function register(): void
2727
public function boot(): void
2828
{
2929
if (Features::hasDataCollections()) {
30-
// Create the _data directory if it doesn't exist
31-
if (! is_dir(Hyde::path('_data'))) {
32-
mkdir(Hyde::path('_data'));
30+
// Create the resources/collections directory if it doesn't exist
31+
if (! is_dir(Hyde::path('resources/collections'))) {
32+
mkdir(Hyde::path('resources/collections'));
3333
}
3434
}
3535
}

packages/framework/tests/Feature/DataCollectionTest.php

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,59 +65,59 @@ public function test_get_markdown_files_method_returns_empty_array_if_the_specif
6565

6666
public function test_get_markdown_files_method_returns_empty_array_if_no_files_are_found_in_specified_directory()
6767
{
68-
mkdir(Hyde::path('_data/foo'));
68+
mkdir(Hyde::path('resources/collections/foo'));
6969
$class = new DataCollection('foo');
7070
$this->assertIsArray($class->getMarkdownFiles());
7171
$this->assertEmpty($class->getMarkdownFiles());
72-
rmdir(Hyde::path('_data/foo'));
72+
rmdir(Hyde::path('resources/collections/foo'));
7373
}
7474

7575
public function test_get_markdown_files_method_returns_an_array_of_markdown_files_in_the_specified_directory()
7676
{
77-
mkdir(Hyde::path('_data/foo'));
78-
Hyde::touch('_data/foo/foo.md');
79-
Hyde::touch('_data/foo/bar.md');
77+
mkdir(Hyde::path('resources/collections/foo'));
78+
Hyde::touch('resources/collections/foo/foo.md');
79+
Hyde::touch('resources/collections/foo/bar.md');
8080

8181
$this->assertEquals([
82-
Hyde::path('_data/foo/bar.md'),
83-
Hyde::path('_data/foo/foo.md'),
82+
Hyde::path('resources/collections/foo/bar.md'),
83+
Hyde::path('resources/collections/foo/foo.md'),
8484
], (new DataCollection('foo'))->getMarkdownFiles());
8585

86-
File::deleteDirectory(Hyde::path('_data/foo'));
86+
File::deleteDirectory(Hyde::path('resources/collections/foo'));
8787
}
8888

8989
public function test_get_markdown_files_method_does_not_include_files_in_subdirectories()
9090
{
91-
mkdir(Hyde::path('_data/foo'));
92-
mkdir(Hyde::path('_data/foo/bar'));
93-
Hyde::touch('_data/foo/foo.md');
94-
Hyde::touch('_data/foo/bar/bar.md');
91+
mkdir(Hyde::path('resources/collections/foo'));
92+
mkdir(Hyde::path('resources/collections/foo/bar'));
93+
Hyde::touch('resources/collections/foo/foo.md');
94+
Hyde::touch('resources/collections/foo/bar/bar.md');
9595
$this->assertEquals([
96-
Hyde::path('_data/foo/foo.md'),
96+
Hyde::path('resources/collections/foo/foo.md'),
9797
], (new DataCollection('foo'))->getMarkdownFiles());
98-
File::deleteDirectory(Hyde::path('_data/foo'));
98+
File::deleteDirectory(Hyde::path('resources/collections/foo'));
9999
}
100100

101101
public function test_get_markdown_files_method_does_not_include_files_with_extensions_other_than_md()
102102
{
103-
mkdir(Hyde::path('_data/foo'));
104-
Hyde::touch('_data/foo/foo.md');
105-
Hyde::touch('_data/foo/bar.txt');
103+
mkdir(Hyde::path('resources/collections/foo'));
104+
Hyde::touch('resources/collections/foo/foo.md');
105+
Hyde::touch('resources/collections/foo/bar.txt');
106106
$this->assertEquals([
107-
Hyde::path('_data/foo/foo.md'),
107+
Hyde::path('resources/collections/foo/foo.md'),
108108
], (new DataCollection('foo'))->getMarkdownFiles());
109-
File::deleteDirectory(Hyde::path('_data/foo'));
109+
File::deleteDirectory(Hyde::path('resources/collections/foo'));
110110
}
111111

112112
public function test_get_markdown_files_method_does_not_remove_files_starting_with_an_underscore()
113113
{
114-
mkdir(Hyde::path('_data/foo'));
115-
Hyde::touch('_data/foo/_foo.md');
114+
mkdir(Hyde::path('resources/collections/foo'));
115+
Hyde::touch('resources/collections/foo/_foo.md');
116116

117117
$this->assertEquals([
118-
Hyde::path('_data/foo/_foo.md'),
118+
Hyde::path('resources/collections/foo/_foo.md'),
119119
], (new DataCollection('foo'))->getMarkdownFiles());
120-
File::deleteDirectory(Hyde::path('_data/foo'));
120+
File::deleteDirectory(Hyde::path('resources/collections/foo'));
121121
}
122122

123123
public function test_static_markdown_helper_returns_new_data_collection_instance()
@@ -127,24 +127,24 @@ public function test_static_markdown_helper_returns_new_data_collection_instance
127127

128128
public function test_static_markdown_helper_discovers_and_parses_markdown_files_in_the_specified_directory()
129129
{
130-
mkdir(Hyde::path('_data/foo'));
131-
Hyde::touch('_data/foo/foo.md');
132-
Hyde::touch('_data/foo/bar.md');
130+
mkdir(Hyde::path('resources/collections/foo'));
131+
Hyde::touch('resources/collections/foo/foo.md');
132+
Hyde::touch('resources/collections/foo/bar.md');
133133

134134
$collection = DataCollection::markdown('foo');
135135

136136
$this->assertContainsOnlyInstancesOf(MarkdownDocument::class, $collection);
137137

138-
File::deleteDirectory(Hyde::path('_data/foo'));
138+
File::deleteDirectory(Hyde::path('resources/collections/foo'));
139139
}
140140

141141
public function test_static_markdown_helper_doest_not_ignore_files_starting_with_an_underscore()
142142
{
143-
mkdir(Hyde::path('_data/foo'));
144-
Hyde::touch('_data/foo/foo.md');
145-
Hyde::touch('_data/foo/_bar.md');
143+
mkdir(Hyde::path('resources/collections/foo'));
144+
Hyde::touch('resources/collections/foo/foo.md');
145+
Hyde::touch('resources/collections/foo/_bar.md');
146146
$this->assertCount(2, DataCollection::markdown('foo'));
147-
File::deleteDirectory(Hyde::path('_data/foo'));
147+
File::deleteDirectory(Hyde::path('resources/collections/foo'));
148148
}
149149

150150
public function test_markdown_facade_returns_same_result_as_static_markdown_helper()
@@ -166,29 +166,29 @@ public function test_data_collection_service_provider_creates_the__data_director
166166
{
167167
config(['hyde.features' => [Features::dataCollections()]]);
168168

169-
File::deleteDirectory(Hyde::path('_data'));
170-
$this->assertFileDoesNotExist(Hyde::path('_data'));
169+
File::deleteDirectory(Hyde::path('resources/collections'));
170+
$this->assertFileDoesNotExist(Hyde::path('resources/collections'));
171171

172172
(new DataCollectionServiceProvider($this->app))->boot();
173173

174-
$this->assertFileExists(Hyde::path('_data'));
174+
$this->assertFileExists(Hyde::path('resources/collections'));
175175
}
176176

177177
public function test_data_collection_service_provider_does_not_create_the__data_directory_feature_is_disabled()
178178
{
179-
File::deleteDirectory(Hyde::path('_data'));
180-
$this->assertFileDoesNotExist(Hyde::path('_data'));
179+
File::deleteDirectory(Hyde::path('resources/collections'));
180+
$this->assertFileDoesNotExist(Hyde::path('resources/collections'));
181181

182182
config(['hyde.features' => []]);
183183
$this->app['config']->set('hyde.data_collection.enabled', false);
184184
(new DataCollectionServiceProvider($this->app))->boot();
185185

186-
$this->assertFileDoesNotExist(Hyde::path('_data'));
186+
$this->assertFileDoesNotExist(Hyde::path('resources/collections'));
187187
}
188188

189189
public function test_class_has_static_source_directory_property()
190190
{
191-
$this->assertEquals('_data', DataCollection::$sourceDirectory);
191+
$this->assertEquals('resources/collections', DataCollection::$sourceDirectory);
192192
}
193193

194194
public function test_source_directory_can_be_changed()

0 commit comments

Comments
 (0)