$readableSchemas * @param string $currentSchema * @return string */ public function render(array $readableSchemas, string $currentSchema): string { $schemas = $this->channelService->channel->schemas->whereIn("name", $readableSchemas); $sidebar = $this->fromConfig(); $sections = []; $usedSchemaNames = []; if ($sidebar->isDefined()) { $sections = $sidebar->get()->sections->map(function (Section $section) use ($currentSchema): SectionData { return new SectionData( label: $section->label, isOpen: $section->items->where("schema", $currentSchema)->isNotEmpty(), items: array_map(fn($item) => $this->renderItem($currentSchema, $item), $section->items->toArray()) ); })->toArray(); $usedSchemaNames =$sidebar->get()->sections->reduce(fn(array $carry, Section $section) => array_merge($carry, $section->items->pluck("schema")->toArray()), []); } $sections[] = new SectionData( label: $sidebar->isDefined() ? "Rest" : "Content", isOpen: $schemas->whereNotIn("name",$usedSchemaNames)->where("name",$currentSchema)->isNotEmpty(), items: array_map(fn($item) => $this->renderItem($currentSchema, $item), $schemas->whereNotIn("name",$usedSchemaNames)->toArray()) ); return view('lucent::sidebar.sidebar', [ 'channel' => $this->channelService->channel, 'sections' => $sections, ])->render(); } private function renderItem(string $currentSchema, Item|Schema $item): ItemData { return match (get_class($item)) { LinkItem::class => new ItemData($item->label, $item->href, false, true), SchemaItem::class => new ItemData($item->label, $this->channelService->channel->lucentUrl . "/content/" . $item->schema, $currentSchema === $item->schema, false), CollectionSchema::class => new ItemData($item->label, $this->channelService->channel->lucentUrl . "/content/" . $item->name, $currentSchema === $item->name, false), FilesSchema::class => new ItemData($item->label, $this->channelService->channel->lucentUrl . "/content/" . $item->name, $currentSchema === $item->name, false), }; } /** * @return Option */ private function fromConfig(): Option { $configPath = base_path(config("lucent.sidebar_path")) . "/sidebar.yaml"; if (!file_exists($configPath)) { return none(); } $yaml = Yaml::parse(file_get_contents($configPath)); if (empty($yaml)) { return none(); } $sidebar = Sidebar::fromArray($yaml); return some($sidebar); } }