37 lines
869 B
PHP
37 lines
869 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class ContentCollection
|
|
{
|
|
public Collection $pages;
|
|
|
|
public function __construct(public string $name)
|
|
{
|
|
$directories = Storage::disk('source')->directories($name);
|
|
$files = Storage::disk('source')->files($name);
|
|
|
|
$pages = collect();
|
|
|
|
foreach ($files as $f) {
|
|
$p = new Page($f);
|
|
$p->collection = $name;
|
|
$pages->push($p);
|
|
}
|
|
|
|
// Go through directories and check for index.md
|
|
foreach ($directories as $dir) {
|
|
if (Storage::disk('source')->exists("$dir/index.md")) {
|
|
$p = new Page("$dir/index.md");
|
|
$p->collection = $name;
|
|
$pages->push($p);
|
|
}
|
|
}
|
|
|
|
$this->pages = $pages;
|
|
}
|
|
}
|