develop
HerrHase 3 years ago
parent d69bbc2357
commit a404ed0789

@ -1,4 +1,5 @@
APP_DEBUG=false
APP_LOCALE=en
DIRECTUS_API_URL=
DIRECTUS_API_TOKEN=

@ -1,4 +1,4 @@
# Super Gear Directus 1.0.0-rc2
# Super Gear Directus 1.0.0-rc3
Project to using a Directus Instance as CMS. Structure is inspired by Laravel, using [FlightPHP](https://github.com/mikecao/flight)
for handle Request.
@ -25,36 +25,4 @@ DIRECTUS_API_TOKEN=
## Repositories
For getting Data use **App\\Respositories\\RepositoryAbstract** to create Repository-Classes.
This is the default class to handle
```PHP
class PageRepository extends RepositoryAbstract
{
/** endpoint */
protected $endpoint = 'pages';
/**
* find single page with a slug,
* page must be published
*
* @param string $slug
* @return array
*/
public function findOneBySlug($slug)
{
if (!$slug) {
$slug = [ '_null' => 'true' ];
}
return $this->queryBuilder
->fields(['title', 'slug', 'content', 'view', 'meta', 'media_teaser.*', 'media_hero.*'])
->aliases('view', 'template')
->filter([
'status' => 'published',
'slug' => $slug
])
->findOne();
}
}
```

@ -0,0 +1,53 @@
<?php
namespace App\Controllers;
use App\Controllers\DirectusControllerAbstract;
use App\Repositories\SiteRepository;
use App\Repositories\PostRepository;
/**
* controller for render feed of posts
*
*
* @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
*
*/
class FeedController extends DirectusControllerAbstract
{
private $limit = 20;
/**
*
*/
protected $page = [
'data' => [
'view' => 'rss'
]
];
/**
* get single page from slug
*
*
* @param string $slug
*/
public function indexAction()
{
$siteRepository = new SiteRepository();
$site = $siteRepository->findOne();
$postRepository = new PostRepository();
$posts = $postRepository->find($this->limit);
// change type
header('Content-Type: text/xml');
$this->render($this->page, [
'site' => $site,
'posts' => $posts
]);
}
}

@ -3,7 +3,7 @@
namespace App\Controllers;
use App\Controllers\DirectusControllerAbstract;
use App\Repositories\Manager;
use App\Repositories\PageRepository;
/**
* controller for page items from directus
@ -36,11 +36,11 @@ class PageController extends DirectusControllerAbstract
*/
public function getAction($slug = NULL)
{
$repository = Manager::get('Page');
$page = $repository->findOneBySlug($slug);
$pageRepository = new PageRepository();
$page = $pageRepository->findOneBySlug($slug);
if (count($page['data']) === 0) {
$this->app->redirect('/404', 301);
$this->app->redirect('/404');
} else {
$this->render($page);
}

@ -0,0 +1,36 @@
<?php
namespace App\Controllers;
use App\Controllers\DirectusControllerAbstract;
use App\Repositories\PostRepository;
/**
* controller for page 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 PostController extends DirectusControllerAbstract
{
/**
* get single page from slug
*
*
* @param string $slug
*/
public function getAction($slug)
{
$repository = new PostRepository();
$post = $repository->findOneBySlug($slug);
if (count($post['data']) === 0) {
$this->app->redirect('/404');
} else {
$this->render($post);
}
}
}

@ -1,51 +0,0 @@
<?php
namespace App\Repositories;
use Exception;
/**
* Manager Class to create Repository Objects that
* are located in App\Repositories\
*
*
* @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
*
*/
class Manager
{
/**
* naming of Repository
* @var string
*/
const NAMESPACE = 'App\Repositories\\';
/**
* naming of Repository
* @var string
*/
const REPOSITORY_SUFFIX = 'Repository';
/**
* getting repository object
*
* @param string $repositoryClass
* @return AbstractRepository
*/
public static function get($repositoryName)
{
$repositoryClass = self::NAMESPACE.$repositoryName.self::REPOSITORY_SUFFIX;
if (!class_exists($repositoryClass)) {
throw new Exception('Repository Class '.$repositoryClass.' not exists!');
}
// create respository object
$repository = new $repositoryClass();
return $repository;
}
}

@ -0,0 +1,83 @@
<?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 PostRepository extends RepositoryAbstract
{
/** endpoint */
protected $endpoint = 'posts';
/**
*
*/
public function find($limit = 20)
{
return $this->queryBuilder
->fields([
'title',
'slug',
'lead',
'content',
'view',
'date_created',
'published_at',
'media_teaser.id',
'media_teaser.description'
])
->aliases('template', 'view')
->filter([
'status' => 'published',
'published_at' => [
'_nnull' => 'true'
]
])
->sort(['published_at'])
->find();
}
/**
* find single page with a slug,
* page must be published
*
* @param string $slug
* @return array
*/
public function findOneBySlug($slug)
{
return $this->queryBuilder
->fields([
'title',
'slug',
'lead',
'content',
'view',
'meta',
'date_created',
'published_at',
'media_teaser.id',
'media_teaser.description',
'media_hero.id',
'media_hero.description',
])
->aliases('template', 'view')
->filter([
'status' => 'published',
'published_at' => [
'_nnull' => 'true'
],
'slug' => $slug
])
->findOne();
}
}

@ -17,7 +17,9 @@
"vlucas/phpdotenv": "5.3.*",
"jenssegers/blade": "1.4.*",
"tentakelfabrik/pirectus": "^0.1.3",
"cocur/slugify": "^4.0"
"cocur/slugify": "^4.0",
"nesbot/carbon": "^2.54",
"mtownsend/read-time": "^2.0"
},
"autoload": {
"psr-4": {

67
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5263bc5e77eb9849e010bbef6fa46c6f",
"content-hash": "a83db35a0da974bc28038b8ae4581142",
"packages": [
{
"name": "cocur/slugify",
@ -1253,6 +1253,71 @@
},
"time": "2021-04-05T01:36:59+00:00"
},
{
"name": "mtownsend/read-time",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/mtownsend5512/read-time.git",
"reference": "b43f178095383bda3cdf606c8a288bf8cacf537e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mtownsend5512/read-time/zipball/b43f178095383bda3cdf606c8a288bf8cacf537e",
"reference": "b43f178095383bda3cdf606c8a288bf8cacf537e",
"shasum": ""
},
"require": {
"php": "^7.4|^8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.3"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Mtownsend\\ReadTime\\Providers\\ReadTimeServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Mtownsend\\ReadTime\\": "src"
},
"files": [
"src/helpers.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Townsend",
"email": "mtownsend5512@gmail.com",
"role": "Developer"
}
],
"description": "A PHP package to show users how long it takes to read content.",
"keywords": [
"Minutes",
"article",
"blog",
"content",
"medium",
"min",
"read",
"reading",
"time"
],
"support": {
"issues": "https://github.com/mtownsend5512/read-time/issues",
"source": "https://github.com/mtownsend5512/read-time/tree/2.0.0"
},
"time": "2021-01-11T13:46:58+00:00"
},
{
"name": "nesbot/carbon",
"version": "2.54.0",

@ -10,10 +10,19 @@ $flight->route('GET /@slug:[a-z0-9\-]+/$', function() use ($flight) {
$position = strlen($flight->request()->url) - 1;
$route = substr_replace($flight->request()->url, '', $position, 1);
$flight->redirect($route);
$flight->redirect($route, 301);
});
$flight->route('GET /404', array(new App\Controllers\PageController, 'notFoundAction'));
$flight->route('GET /feed', array(new App\Controllers\FeedController, 'indexAction'));
$flight->route('GET /blog/@slug:[a-z0-9\-]+$', array(new App\Controllers\PostController, 'getAction'));
$flight->route('GET /(@slug:[a-z0-9\-]+$)', array(new App\Controllers\PageController, 'getAction'));
$flight->start();
try {
$flight->start();
} catch (\Exception $exception) {
echo $exception->getMessage();
}

@ -2,8 +2,6 @@
@inject('siteRepository', 'App\Repositories\SiteRepository')
@inject('menuRepository', 'App\Repositories\MenuRepository')
@inject('markdownHelper', 'App\Helpers\MarkdownHelper')
@php
$site = $siteRepository->findOne();
$menuItems = $menuRepository->findByName('main');

@ -0,0 +1,53 @@
@extends('layout')
{{-- pretend duplicate content --}}
@push('head')
<meta name="robots" content="noindex,follow" />
@endpush
{{-- inject helper for content & repositories --}}
@inject('markdownHelper', 'App\Helpers\MarkdownHelper')
@inject('postRepository', 'App\Repositories\PostRepository')
@php
$posts = $postRepository->find();
@endphp
@section('content')
<h1>
{{ $page['data']['title'] }}
</h1>
<div class="content">
{!! $markdownHelper->parse($page['data']['content']) !!}
</div>
@if (count($posts) > 0)
@foreach($posts['data'] as $post)
<a class="post" href="/blog/{{ $post['slug'] }}">
<header class="post__header">
<h2 class="post__title">
{{ $post['title'] }}
</h2>
@include('partials.date', ['post' => $post])
@include('partials.readtime', ['post' => $post])
@if (isset($post['media_teaser']['id']))
<div class="post__teaser">
<img src="{{ assetsUrl($post['media_teaser']['id']) }}" alt="{{ $post['media_teaser']['description'] }}" />
</div>
@endif
</header>
<div class="content post__lead">
{!! $markdownHelper->parse($post['lead']) !!}
</div>
</div>
@endforeach
@else
<div class="post">
<p>
Nothing!
</p>
</div>
@endif
@endsection

@ -0,0 +1,5 @@
<div class="post__date">
<time datetime="{{ $post['published_at'] }}">
{{ Carbon\Carbon::parse($post['published_at'])->diffForHumans() }}
</time>
</div>

@ -0,0 +1,10 @@
@php
$content = $post['lead'].$post['content'];
$readtime = (new \Mtownsend\ReadTime\ReadTime($content))->timeOnly(true)->setTranslation([
'minute' => ''
])->get();
@endphp
<div class="post__readtime">
Reading time {{ $readtime }} Minutes
</div>

@ -0,0 +1,17 @@
@extends('layout')
@inject('markdownHelper', 'App\Helpers\MarkdownHelper')
@section('content')
<h1>
{{ $page['data']['title'] }}
</h1>
<div class="content content--lead">
{!! $markdownHelper->parse($page['data']['lead']) !!}
</div>
<div class="content">
{!! $markdownHelper->parse($page['data']['content']) !!}
</div>
@endsection

@ -0,0 +1,38 @@
@inject('markdownHelper', 'App\Helpers\MarkdownHelper')
@php
if (isset($_SERVER['HTTPS'])) {
$http = 'https';
} else {
$http = 'http';
}
$base_url = $http.'://'.$_SERVER['SERVER_NAME'];
@endphp
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ $site['data']['title'] }}</title>
<atom:link href="{{ $base_url }}/feed" rel="self" type="application/rss+xml" />
<link>{{ $base_url }}/blog</link>
<description>{{ $site['data']['description'] }}</description>
<lastBuildDate>{{ date(DATE_RSS) }}</lastBuildDate>
<language>{{ $_ENV['APP_LOCALE'] }}-{{ strtoupper($_ENV['APP_LOCALE']) }}</language>
@foreach($posts['data'] as $post)
<item>
<title>{{ $post['title'] }}</title>
<link>{{ $base_url.'/blog/'.$post['slug'] }}</link>
<pubDate>{{ date(DATE_RSS, strtotime($post['published_at'])) }}</pubDate>
<description>
<![CDATA[
{!! $markdownHelper->parse($post['lead']) !!}
{!! $markdownHelper->parse($post['content']) !!}
]]>
</description>
<guid isPermaLink="false">{{ $post['slug'] }}</guid>
</item>
@endforeach
</channel>
</rss>
Loading…
Cancel
Save