From 9b4454e321082f743d7338c56360ca08a788c2f0 Mon Sep 17 00:00:00 2001 From: "David T. Sadler" Date: Fri, 21 Aug 2020 15:51:26 +0100 Subject: Refactor configuration --- config.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'config.php') diff --git a/config.php b/config.php index 8a91883..2c5fb5b 100644 --- a/config.php +++ b/config.php @@ -17,9 +17,17 @@ return [ 'posts' => [ // Default author, if not provided in a post 'author' => 'David T. Sadler', - 'date' => $now->timestamp, 'sort' => '-date', 'path' => '/posts', + 'filter' => function ($item) use ($now) { + // Include every post if in development. + if (!$item->production) { + return true; + } + // Only publish posts that have a date and which is not in the future. + $date = $item->getDate(); + return $date ? $date <= $now : false; + } ], 'tags' => [ 'path' => '/tags/{filename}', @@ -35,8 +43,9 @@ return [ ], // Helpers - 'getDate' => function ($page) { - return $page->date ? Carbon::createFromFormat('U', $page->date) : null; + 'getDate' => function ($page) use ($now) { + // Use post date if one has been specified. Otherwise default to today's date in development. + return $page->date ? Carbon::createFromFormat('U', $page->date) : ($page->production ? null : $now); }, 'allTags' => function ($page, $allPosts) { -- cgit v1.2.3-13-gbd6f