Added dynamic page titles

This commit is contained in:
Chris Kankiewicz
2020-01-07 12:05:44 -07:00
parent 7b5e2c5994
commit 13594b5476
3 changed files with 17 additions and 1 deletions

View File

@@ -85,6 +85,7 @@ class DirectoryController
}
return $this->view->render($response, 'index.twig', [
'title' => $this->relativePath($path),
'breadcrumbs' => $this->breadcrumbs($path),
'files' => $files,
'is_root' => $this->isRoot($path),
@@ -93,6 +94,20 @@ class DirectoryController
]);
}
/**
* Return the relative path given a full path.
*
* @param string $path
*
* @return string
*/
protected function relativePath(string $path): string
{
return Collection::make(explode('/', $path))->diff(
explode('/', $this->container->get('base_path'))
)->filter()->implode('/');
}
/**
* Build an array of breadcrumbs for a given path.
*

View File

@@ -1,5 +1,6 @@
{% extends "layouts/app.twig" %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
{% include "components/header.twig" %}

View File

@@ -7,7 +7,7 @@
<link rel="stylesheet" href="{{ asset('app.css') }}">
<title>Directory Lister</title>
<title>{% block title %}{% endblock %} &bull; Directory Lister</title>
<div id="app" class="flex flex-col min-h-screen font-mono {{ config('dark_mode') ? 'dark-mode' : '' }}">
{% block content %}{% endblock %}