diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2020-03-27 16:26:54 +0000 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2020-03-27 16:26:54 +0000 |
| commit | b6040ea2ab6d4510fab5e3911132b0deb7017642 (patch) | |
| tree | d6da338de8c3101e0e4037f7d85671a0fadd4767 | |
| parent | c09305bfcf14707ef8c6b46e4e39a03c42a5c746 (diff) | |
Allow posts to be unpublished or scheduled in the future
| -rw-r--r-- | config.php | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -1,6 +1,9 @@ <?php use Illuminate\Support\Str; +use Carbon\Carbon; + +$now = Carbon::now(); return [ 'baseUrl' => 'http://localhost:3000', @@ -17,6 +20,11 @@ return [ 'author' => 'David T. Sadler', 'sort' => '-date', 'path' => '/posts/{date|Y-m-d}/{filename}', + 'filter' => function ($item) use ($now) { + // 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}', @@ -33,7 +41,7 @@ return [ // Helpers 'getDate' => function ($page) { - return Datetime::createFromFormat('U', $page->date); + return $page->date ? Carbon::createFromFormat('U', $page->date) : null; }, 'allTags' => function ($page, $allPosts) { |
