sort posts on date and allow posts to be a level deeper

master
eater 4 years ago
parent dde438949a
commit 4a6cefa3d1
Signed by: eater
GPG Key ID: AD2560A0F84F0759

@ -120,7 +120,7 @@ class Blog
); );
$app->get( $app->get(
'/post/{post}', '/post/{post:.+}',
function (Request $request, Response $response, $args) { function (Request $request, Response $response, $args) {
$post = $this->posts[$args['post']] ?? false; $post = $this->posts[$args['post']] ?? false;
if ( ! $post) { if ( ! $post) {
@ -213,7 +213,7 @@ class Blog
private function parseObjects($path, $registerTags = false) private function parseObjects($path, $registerTags = false)
{ {
$objectBase = realpath($path); $objectBase = realpath($path);
$objects = glob($objectBase."/*.md"); $objects = array_merge(glob($objectBase."/*.md") ?: [], glob($objectBase."/*/*.md") ?: []);
$objectsColl = []; $objectsColl = [];
foreach ($objects as $object) { foreach ($objects as $object) {
@ -263,6 +263,11 @@ class Blog
} }
$this->posts = $this->parseObjects(__DIR__."/../data/posts", true); $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->pages = $this->parseObjects(__DIR__."/../data/pages");
$this->games = $this->parseObjects(__DIR__."/../data/games"); $this->games = $this->parseObjects(__DIR__."/../data/games");

Loading…
Cancel
Save