diff --git a/app/Controllers/DirectoryController.php b/app/Controllers/DirectoryController.php index 2e99fd2..eeae838 100644 --- a/app/Controllers/DirectoryController.php +++ b/app/Controllers/DirectoryController.php @@ -65,8 +65,7 @@ class DirectoryController 'files' => $search ? $files->name( sprintf('/(?:.*)%s(?:.*)/i', preg_quote($search, '/')) ) : $files->depth(0), - 'title' => $this->relativePath($path), - 'breadcrumbs' => $this->breadcrumbs($path), + 'relative_path' => $this->relativePath($path), 'is_root' => $this->isRoot($path), 'readme' => $this->readme($path), 'search' => $search, @@ -87,28 +86,6 @@ class DirectoryController )->filter()->implode('/'); } - /** - * Build an array of breadcrumbs for a given path. - * - * @param string $path - * - * @return array - */ - protected function breadcrumbs(string $path): array - { - $breadcrumbs = Collection::make(explode('/', $path))->diff( - explode('/', $this->container->get('base_path')) - )->filter(); - - return $breadcrumbs->filter(function (string $crumb) { - return $crumb !== '.'; - })->reduce(function (array $carry, string $crumb) { - $carry[$crumb] = end($carry) . "/{$crumb}"; - - return $carry; - }, []); - } - /** * Determine if a provided path is the root path. * diff --git a/app/Providers/TwigProvider.php b/app/Providers/TwigProvider.php index 05c0a4e..51537ed 100644 --- a/app/Providers/TwigProvider.php +++ b/app/Providers/TwigProvider.php @@ -15,6 +15,7 @@ class TwigProvider /** @const Constant description */ protected const VIEW_FUNCTIONS = [ ViewFunctions\Asset::class, + ViewFunctions\Breadcrumbs::class, ViewFunctions\Config::class, ViewFunctions\Icon::class, ViewFunctions\Markdown::class, diff --git a/app/ViewFunctions/Breadcrumbs.php b/app/ViewFunctions/Breadcrumbs.php new file mode 100644 index 0000000..415053d --- /dev/null +++ b/app/ViewFunctions/Breadcrumbs.php @@ -0,0 +1,33 @@ +diff( + explode('/', $this->container->get('base_path')) + )->filter(); + + return $breadcrumbs->filter(function (string $crumb) { + return $crumb !== '.'; + })->reduce(function (array $carry, string $crumb) { + $carry[$crumb] = end($carry) . "/{$crumb}"; + + return $carry; + }, []); + } +} diff --git a/app/resources/views/components/header.twig b/app/resources/views/components/header.twig index c6481bb..18f391d 100644 --- a/app/resources/views/components/header.twig +++ b/app/resources/views/components/header.twig @@ -3,7 +3,7 @@