Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Group templates by name for block themes (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssang authored Aug 12, 2024
1 parent 8a2f798 commit c1c2f57
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 c1c2f57

Please sign in to comment.