develop
HerrHase 3 years ago
parent 1fa88556a2
commit 6902826d15

@ -23,6 +23,7 @@ class PageController extends DirectusControllerAbstract
protected $page404 = [
'data' => [
'title' => '404',
'slug' => '404',
'view' => 'page/404'
]
];

@ -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;
}

@ -0,0 +1,37 @@
<?php
namespace App\Repositories;
use App\Repositories\RepositoryAbstract;
/**
* request pages items from directus
*
* @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
*
*/
class SiteRepository extends RepositoryAbstract
{
/** endpoint */
protected $endpoint = 'site';
/**
* find single page with a slug,
* page must be published
*
* @param string $slug
* @return array
*/
public function findOne()
{
return $this->queryBuilder
->fields([
'title', 'description', 'logo'
])
->aliases('logo[id]', 'logo')
->findOne();
}
}

@ -1,13 +1,19 @@
@inject('pageRepository', 'App\Repositories\PageRepository')
@inject('siteRepository', 'App\Repositories\SiteRepository')
@inject('markdownHelper', 'App\Helpers\MarkdownHelper')
@php
$site = $siteRepository->findOne();
@endphp
<!DOCTYPE html>
<html lang="de-DE">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>
Elina Penner | {{ $page['data']['title'] }}
{{ title($page, $site) }}
</title>
@include('partials.meta')
@ -24,6 +30,7 @@
<header class="site-header">
<h1 class="site-header__title">
Super Gear Directus
<img src="{{ assetsUrl($site['data']['logo']) }}" />
</h1>
</header>

Loading…
Cancel
Save