Skip to content

Commit

Permalink
Group templates by name for block themes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssang committed Jul 18, 2024
1 parent 8a2f798 commit 9e6d005
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Roots\Acorn\Sage\Concerns;

use Illuminate\Support\Str;

trait FiltersTemplates
{
/**
Expand Down Expand Up @@ -35,13 +37,12 @@ public function filterTemplateHierarchy($files)
$templates = array_diff($templates, $pages);
}

if (($index = array_search('index.php', $files)) !== false) {
unset($files[$index]);

$templates[] = 'index.php';
}

return [...$pages, ...$files, ...$templates];
return collect([...$pages, ...$files, ...$templates])
->groupBy(function ($item) {
return Str::of($item)->afterLast('/')->before('.');
})
->flatten()
->toArray();
}

/**
Expand Down

0 comments on commit 9e6d005

Please sign in to comment.