diff --git a/app/Controllers/PageController.php b/app/Controllers/PageController.php index 7b809a8..6154445 100644 --- a/app/Controllers/PageController.php +++ b/app/Controllers/PageController.php @@ -23,6 +23,7 @@ class PageController extends DirectusControllerAbstract protected $page404 = [ 'data' => [ 'title' => '404', + 'slug' => '404', 'view' => 'page/404' ] ]; diff --git a/app/Functions/Blade.php b/app/Functions/Blade.php index 448580e..39d06ef 100644 --- a/app/Functions/Blade.php +++ b/app/Functions/Blade.php @@ -73,3 +73,47 @@ function canonical() return $canoncial; } + +/** + * getting title for head + * + * @param array $page + * @param array $site + * @return string + */ +function title($page, $site) +{ + $title = []; + + if ($site['data']['title']) { + $title[] = $site['data']['title']; + } + + // if not homepage set page title first + if ($page['data']['slug']) { + array_unshift($title, $page['data']['title']); + } else { + $title[] = $page['data']['title']; + } + + return join(' | ', $title); +} + +/** + * getting url for assets of directus api + * + * @param string string + * @param array array + * @return string + * + */ +function assetsUrl(string $id, array $options = NULL) +{ + $query = NULL; + + if ($options) { + $query = '?'.http_build_query($options); + } + + return $_ENV['DIRECTUS_API_URL'].'/assets/'.$id.$query; +} diff --git a/app/Repositories/SiteRepository.php b/app/Repositories/SiteRepository.php new file mode 100644 index 0000000..f51a3e2 --- /dev/null +++ b/app/Repositories/SiteRepository.php @@ -0,0 +1,37 @@ +queryBuilder + ->fields([ + 'title', 'description', 'logo' + ]) + ->aliases('logo[id]', 'logo') + ->findOne(); + } +} diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php index fc59263..b3384de 100644 --- a/resources/views/layout.blade.php +++ b/resources/views/layout.blade.php @@ -1,13 +1,19 @@ @inject('pageRepository', 'App\Repositories\PageRepository') +@inject('siteRepository', 'App\Repositories\SiteRepository') + @inject('markdownHelper', 'App\Helpers\MarkdownHelper') +@php + $site = $siteRepository->findOne(); +@endphp +