76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This class handles anything to do with reading files
|
|
* from the "site" directory and building out the
|
|
* collections and page array, and populating
|
|
* page objects with their relevant data.
|
|
*
|
|
* It also handles folders that need to be ignored
|
|
* such as "assets".
|
|
*/
|
|
|
|
namespace App\Build;
|
|
|
|
use App\Models\Page;
|
|
use Illuminate\Contracts\Filesystem\Filesystem;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
|
|
use function Illuminate\Filesystem\join_paths;
|
|
|
|
class SiteParser
|
|
{
|
|
const IGNORED_DIRECTORIES = ["assets", "_"];
|
|
protected Filesystem $sourceDisk;
|
|
protected Filesystem $targetDisk;
|
|
protected array $paths;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->sourceDisk = Storage::disk('source');
|
|
$this->targetDisk = Storage::disk('build_local');
|
|
}
|
|
|
|
/**
|
|
* Get all the pages from the source directory
|
|
*
|
|
* @return Collection<App\Models\Page>
|
|
*/
|
|
public function getPages(): Collection
|
|
{
|
|
$files = $this->sourceDisk->files(recursive: true);
|
|
foreach (self::IGNORED_DIRECTORIES as $ignore) {
|
|
$files = array_filter($files, fn($path) => !str_starts_with($path, $ignore));
|
|
}
|
|
|
|
$pages = collect();
|
|
|
|
// Set up a structure
|
|
foreach ($files as $f) {
|
|
$pages->push(new Page($f));
|
|
}
|
|
|
|
return $pages;
|
|
}
|
|
|
|
public function slugFromFilename(string $filename): string
|
|
{
|
|
return Str::of(basename($filename))->remove(".md")->remove(".blade.php")->slug()->toString();
|
|
}
|
|
|
|
public function getOutputPath(string $filename): string {}
|
|
|
|
|
|
/**
|
|
* Parse all content collections and sub collections.
|
|
* Return a collection of ContentCollection objects
|
|
* with the correct data populated based on front
|
|
* matter and config.
|
|
*
|
|
* @return Collection
|
|
*/
|
|
// public function collections(): Collection {}
|
|
}
|