From 4a6cefa3d13e5a6caf3153812b273d33803aa200 Mon Sep 17 00:00:00 2001 From: eater <=@eater.me> Date: Wed, 27 May 2020 20:53:40 +0200 Subject: [PATCH] sort posts on date and allow posts to be a level deeper --- src/Blog.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Blog.php b/src/Blog.php index 1580f34..245271f 100644 --- a/src/Blog.php +++ b/src/Blog.php @@ -120,7 +120,7 @@ class Blog ); $app->get( - '/post/{post}', + '/post/{post:.+}', function (Request $request, Response $response, $args) { $post = $this->posts[$args['post']] ?? false; if ( ! $post) { @@ -213,7 +213,7 @@ class Blog private function parseObjects($path, $registerTags = false) { $objectBase = realpath($path); - $objects = glob($objectBase."/*.md"); + $objects = array_merge(glob($objectBase."/*.md") ?: [], glob($objectBase."/*/*.md") ?: []); $objectsColl = []; foreach ($objects as $object) { @@ -263,6 +263,11 @@ class Blog } $this->posts = $this->parseObjects(__DIR__."/../data/posts", true); + + uasort($this->posts, function ($a, $b) { + return $b['meta']['date']->getTimestamp() - $a['meta']['date']->getTimestamp(); + }); + $this->pages = $this->parseObjects(__DIR__."/../data/pages"); $this->games = $this->parseObjects(__DIR__."/../data/games");