Skip to content
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

Exclude files starting with an underscore from being compiled into pages, fix #220 #254

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Exclude files starting with an _underscore from being discovered
  • Loading branch information
caendesilva committed May 2, 2022
commit 0dcdcb6a35969094533429345a0108915db388f4
23 changes: 13 additions & 10 deletions src/Services/CollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Hyde\Framework\Models\DocumentationPage;
use Hyde\Framework\Models\MarkdownPage;
use Hyde\Framework\Models\MarkdownPost;
use JetBrains\PhpStorm\Pure;

/**
* Contains service methods to return helpful collections of arrays and lists.
* @see \Tests\Feature\Services\CollectionServiceTest
*/
class CollectionService
{
Expand All @@ -22,7 +22,6 @@ class CollectionService
*
* @example CollectionService::getSourceFileListForModel(BladePage::class)
*/
#[Pure]
public static function getSourceFileListForModel(string $model): array|false
{
if ($model == BladePage::class) {
Expand All @@ -49,13 +48,14 @@ public static function getSourceFileListForModel(string $model): array|false
*
* @return array
*/
#[Pure]
public static function getBladePageList(): array
{
$array = [];

foreach (glob(Hyde::path('_pages/*.blade.php')) as $filepath) {
$array[] = basename($filepath, '.blade.php');
if (!str_starts_with(basename($filepath), '_')) {
$array[] = basename($filepath, '.blade.php');
}
}

return $array;
Expand All @@ -66,13 +66,14 @@ public static function getBladePageList(): array
*
* @return array
*/
#[Pure]
public static function getMarkdownPageList(): array
{
$array = [];

foreach (glob(Hyde::path('_pages/*.md')) as $filepath) {
$array[] = basename($filepath, '.md');
if (!str_starts_with(basename($filepath), '_')) {
$array[] = basename($filepath, '.md');
}
}

return $array;
Expand All @@ -83,13 +84,14 @@ public static function getMarkdownPageList(): array
*
* @return array
*/
#[Pure]
public static function getMarkdownPostList(): array
{
$array = [];

foreach (glob(Hyde::path('_posts/*.md')) as $filepath) {
$array[] = basename($filepath, '.md');
if (!str_starts_with(basename($filepath), '_')) {
$array[] = basename($filepath, '.md');
}
}

return $array;
Expand All @@ -100,13 +102,14 @@ public static function getMarkdownPostList(): array
*
* @return array
*/
#[Pure]
public static function getDocumentationPageList(): array
{
$array = [];

foreach (glob(Hyde::path('_docs/*.md')) as $filepath) {
$array[] = basename($filepath, '.md');
if (!str_starts_with(basename($filepath), '_')) {
$array[] = basename($filepath, '.md');
}
}

return $array;
Expand Down
20 changes: 12 additions & 8 deletions tests/Feature/Services/CollectionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
use Hyde\Framework\Services\CollectionService;
use Tests\TestCase;

/**
* @covers \Hyde\Framework\Services\CollectionService
*/
class CollectionServiceTest extends TestCase
{
public function setUp(): void
{
parent::setUp();

// backupDirectory(Hyde::path('_docs'));
// deleteDirectory(Hyde::path('_docs'));
}

public function test_class_exists()
{
$this->assertTrue(class_exists(CollectionService::class));
Expand All @@ -40,6 +35,15 @@ public function test_get_media_asset_files()
$this->assertTrue(is_array(CollectionService::getMediaAssetFiles()));
}

public function test_files_starting_with_underscore_are_ignored()
{
touch(Hyde::path('_posts/_foo.md'));
$this->assertNotContains('_foo', CollectionService::getMarkdownPostList());
$this->assertNotContains('foo', CollectionService::getMarkdownPostList());
unlink(Hyde::path('_posts/_foo.md'));
}


private function testListUnit(string $model, string $path)
{
touch(Hyde::path($path));
Expand Down