+ Nothing! +
+diff --git a/.env.example b/.env.example index c5f35f6..79b0650 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ APP_DEBUG=false +APP_LOCALE=en DIRECTUS_API_URL= DIRECTUS_API_TOKEN= \ No newline at end of file diff --git a/README.md b/README.md index 1dc9e28..1618cac 100644 --- a/README.md +++ b/README.md @@ -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(); - } -} -``` diff --git a/app/Controllers/FeedController.php b/app/Controllers/FeedController.php new file mode 100644 index 0000000..6587bc3 --- /dev/null +++ b/app/Controllers/FeedController.php @@ -0,0 +1,53 @@ + [ + '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 + ]); + } +} diff --git a/app/Controllers/PageController.php b/app/Controllers/PageController.php index 6154445..c30fac7 100644 --- a/app/Controllers/PageController.php +++ b/app/Controllers/PageController.php @@ -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); } diff --git a/app/Controllers/PostController.php b/app/Controllers/PostController.php new file mode 100644 index 0000000..b1bc0cb --- /dev/null +++ b/app/Controllers/PostController.php @@ -0,0 +1,36 @@ +findOneBySlug($slug); + + if (count($post['data']) === 0) { + $this->app->redirect('/404'); + } else { + $this->render($post); + } + } +} diff --git a/app/Repositories/Manager.php b/app/Repositories/Manager.php deleted file mode 100644 index 9c792f7..0000000 --- a/app/Repositories/Manager.php +++ /dev/null @@ -1,51 +0,0 @@ -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(); + } +} diff --git a/composer.json b/composer.json index cbae854..43c36e2 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index 13c9fc9..fb2b52b 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/public/index.php b/public/index.php index b6499e5..2fc3d02 100644 --- a/public/index.php +++ b/public/index.php @@ -9,11 +9,20 @@ $flight->route('GET /@slug:[a-z0-9\-]+/$', function() use ($flight) { // getting position and build route $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(); +} diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php index 566e372..ecfd394 100644 --- a/resources/views/layout.blade.php +++ b/resources/views/layout.blade.php @@ -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'); diff --git a/resources/views/page/blog.blade.php b/resources/views/page/blog.blade.php new file mode 100644 index 0000000..ce4aa63 --- /dev/null +++ b/resources/views/page/blog.blade.php @@ -0,0 +1,53 @@ +@extends('layout') + +{{-- pretend duplicate content --}} +@push('head') + +@endpush + +{{-- inject helper for content & repositories --}} +@inject('markdownHelper', 'App\Helpers\MarkdownHelper') +@inject('postRepository', 'App\Repositories\PostRepository') + +@php + $posts = $postRepository->find(); +@endphp + +@section('content') + +
+ Nothing! +
+