diff --git a/src/Models/DocumentationSidebar.php b/src/Models/DocumentationSidebar.php new file mode 100644 index 00000000..7b32f0dc --- /dev/null +++ b/src/Models/DocumentationSidebar.php @@ -0,0 +1,36 @@ +push($item); + + return $this; + } + + public function sortItems(): self + { + return $this->sortBy('priority') + ->values(); // Reset the keys to consecutively numbered indexes: + } + + public function getCollection(): self + { + return $this; + } +} \ No newline at end of file diff --git a/src/Models/DocumentationSidebarItem.php b/src/Models/DocumentationSidebarItem.php new file mode 100644 index 00000000..436f62cc --- /dev/null +++ b/src/Models/DocumentationSidebarItem.php @@ -0,0 +1,49 @@ +label = $label; + $this->destination = $destination; + $this->priority = $priority ?? $this->findPriorityInConfig($destination); + } + + protected function findPriorityInConfig(string $slug): int + { + $orderIndexArray = config('hyde.documentationPageOrder', []); + + if (! in_array($slug, $orderIndexArray)) { + return 500; + } + + return array_search($slug, $orderIndexArray); // + 250? + } + + public static function parseFromFile(string $documentationPageSlug): static + { + $matter = YamlFrontMatter::markdownCompatibleParse( + file_get_contents(Hyde::path('_docs/' . $documentationPageSlug . '.md')) + )->matter(); + + return new static( + $matter['label'] ?? Hyde::titleFromSlug($documentationPageSlug), + $documentationPageSlug, + $matter['priority'] ?? null + ); + } +} \ No newline at end of file