Fixed incorrect breadcrumbs when path contains a directory named '0'

This commit is contained in:
Chris Kankiewicz
2020-04-13 12:38:33 -07:00
parent b46aeab614
commit 36911c73cb
2 changed files with 6 additions and 10 deletions

View File

@@ -39,19 +39,15 @@ class Breadcrumbs extends ViewFunction
*/
public function __invoke(string $path)
{
$breadcrumbs = Str::explode($path, $this->directorySeparator)->diff(
return Str::explode($path, $this->directorySeparator)->diff(
explode($this->directorySeparator, $this->container->get('base_path'))
)->filter(function ($value): bool {
return $value !== null;
});
return $breadcrumbs->filter(function (string $crumb) {
return $crumb !== '.';
})->reduce(function (Collection $carry, string $crumb) {
)->filter(function (string $crumb): bool {
return ! in_array($crumb, [null, '.']);
})->reduce(function (Collection $carry, string $crumb): Collection {
return $carry->put($crumb, ltrim(
$carry->last() . $this->directorySeparator . rawurlencode($crumb), $this->directorySeparator
));
}, new Collection)->map(function (string $path): string {
}, new Collection)->map(function (string $path, string $name): string {
return sprintf('?dir=%s', $path);
});
}

View File

@@ -5,7 +5,7 @@
{{ translate('home') }}
</a>
{% if path %}
{% if path is not null %}
{% for name, path in breadcrumbs(path) %}
/ <a href="{{ path }}" class="inline-block hover:underline">{{ name }}</a>
{% endfor %}