Browse Source

adding #1 #3 #4

develop
HerrHase 3 years ago
parent
commit
6902826d15
4 changed files with 90 additions and 1 deletions
  1. +1
    -0
      app/Controllers/PageController.php
  2. +44
    -0
      app/Functions/Blade.php
  3. +37
    -0
      app/Repositories/SiteRepository.php
  4. +8
    -1
      resources/views/layout.blade.php

+ 1
- 0
app/Controllers/PageController.php View File

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


+ 44
- 0
app/Functions/Blade.php View File

@ -73,3 +73,47 @@ function canonical()
return $canoncial; 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;
}

+ 37
- 0
app/Repositories/SiteRepository.php View File

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

+ 8
- 1
resources/views/layout.blade.php View File

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


Loading…
Cancel
Save