| @@ -13,8 +13,9 @@ | ||
| 13 | 13 | |
| 14 | 14 | use WindPressDeps\Symfony\Component\Finder\Finder; |
| 15 | 15 | use Timber\LocationManager; |
| 16 | 16 | use Timber\Timber; |
| 17 | +use WindPress\WindPress\Core\Scanner\FileScanner; | |
| 17 | 18 | /** |
| 18 | 19 | * @author Joshua Gugun Siagian <suabahasa@gmail.com> |
| 19 | 20 | */ |
| 20 | 21 | class Compile |
| @@ -30,21 +31,19 @@ | ||
| 30 | 31 | return $this->get_contents($metadata); |
| 31 | 32 | } |
| 32 | 33 | public function get_contents($metadata): array |
| 33 | 34 | { |
| 34 | - $contents = []; | |
| 35 | - $paths = LocationManager::get_locations(); | |
| 36 | - $paths = array_unique(array_filter(array_merge(...array_values($paths)), fn($path) => $path !== '/')); | |
| 37 | - $finder = new Finder(); | |
| 38 | - $finder->in($paths); | |
| 39 | - $finder->files()->name('*.twig'); | |
| 40 | - do_action('a!windpress/integration/timber/compile:get_contents.finder', $finder); | |
| 41 | - foreach ($finder as $file) { | |
| 42 | - $template_file = $file->getPathname(); | |
| 43 | - if (!is_readable($template_file)) { | |
| 44 | - continue; | |
| 35 | + return FileScanner::scan_files('timber', static function (): \Generator { | |
| 36 | + $paths = LocationManager::get_locations(); | |
| 37 | + $paths = array_unique(array_filter(array_merge(...array_values($paths)), static fn($path) => is_string($path) && $path !== '/' && is_dir($path))); | |
| 38 | + if ($paths === []) { | |
| 39 | + return; | |
| 45 | 40 | } |
| 46 | - $contents[] = ['name' => $file->getRelativePathname(), 'content' => $file->getContents()]; | |
| 47 | - } | |
| 48 | - return ['metadata' => ['next_batch' => \false, 'total_batches' => 1], 'contents' => $contents]; | |
| 41 | + $finder = new Finder(); | |
| 42 | + $finder->in($paths)->files()->name('*.twig'); | |
| 43 | + do_action('a!windpress/integration/timber/compile:get_contents.finder', $finder); | |
| 44 | + foreach ($finder as $file) { | |
| 45 | + yield ['path' => $file->getPathname(), 'name' => $file->getRelativePathname()]; | |
| 46 | + } | |
| 47 | + }, $metadata['next_batch'] ?? \false); | |
| 49 | 48 | } |
| 50 | 49 | } |