Skip to content

Remove underscore filter from Markdown DataCollections #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ This serves two purposes:
- for new features.

### Changed
- for changes in existing functionality.
- The DataCollection module now no longers filters out files starting with an underscore

### Deprecated
- for soon-to-be removed features.
2 changes: 1 addition & 1 deletion docs/collections.md
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ To make collections easy to use and understand, Hyde makes a few assumptions abo
3. Data collections are automatically generated when you use the Facade you will learn about below.
4. When using one of the facades, you need to specify the collection name, this name is the name of the subdirectory.
5. Each subdirectory should probably only have the same filetype to prevent developer confusion, but this is not enforced.
6. Files starting with an underscore are ignored by Hyde.
6. Unlike Markdown pages, files starting with underscores are not ignored.
7. You can customize the base `_data` directory through a service provider.


Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@
use Illuminate\Support\Collection;

/**
* Generates Laravel Collections from static data files,
* such as Markdown components and YAML files.
* Automatically generates Laravel Collections from static data files,
* such as Markdown components and YAML files using Hyde Autodiscovery.
*
* @see \Hyde\Framework\Testing\Feature\DataCollectionTest
*/
@@ -56,11 +56,9 @@ public static function markdown(string $key): DataCollection
{
$collection = new DataCollection($key);
foreach ($collection->getMarkdownFiles() as $file) {
if (! str_starts_with(basename($file), '_')) {
$collection->push(
(new MarkdownFileService($file))->get()
);
}
$collection->push(
(new MarkdownFileService($file))->get()
);
}

return $collection->getCollection();
16 changes: 14 additions & 2 deletions packages/framework/tests/Feature/DataCollectionTest.php
Original file line number Diff line number Diff line change
@@ -113,6 +113,18 @@ public function test_get_markdown_files_method_does_not_include_files_with_exten
File::deleteDirectory(Hyde::path('_data/foo'));
}

// test get markdown files method does not remove files starting with an underscore
public function test_get_markdown_files_method_does_not_remove_files_starting_with_an_underscore()
{
mkdir(Hyde::path('_data/foo'));
Hyde::touch(('_data/foo/_foo.md'));

$this->assertEquals([
Hyde::path('_data/foo/_foo.md'),
], (new DataCollection('foo'))->getMarkdownFiles());
File::deleteDirectory(Hyde::path('_data/foo'));
}

public function test_static_markdown_helper_returns_new_data_collection_instance()
{
$this->assertInstanceOf(DataCollection::class, DataCollection::markdown('foo'));
@@ -131,12 +143,12 @@ public function test_static_markdown_helper_discovers_and_parses_markdown_files_
File::deleteDirectory(Hyde::path('_data/foo'));
}

public function test_static_markdown_helper_ignores_files_starting_with_an_underscore()
public function test_static_markdown_helper_doest_not_ignore_files_starting_with_an_underscore()
{
mkdir(Hyde::path('_data/foo'));
Hyde::touch(('_data/foo/foo.md'));
Hyde::touch(('_data/foo/_bar.md'));
$this->assertCount(1, DataCollection::markdown('foo'));
$this->assertCount(2, DataCollection::markdown('foo'));
File::deleteDirectory(Hyde::path('_data/foo'));
}