summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2020-08-21 15:51:26 +0100
committerDavid T. Sadler <davidtsadler@googlemail.com>2020-08-21 15:51:26 +0100
commit9b4454e321082f743d7338c56360ca08a788c2f0 (patch)
tree3dd068b313dea698cc222c2eccc072ce70f6fb77
parenta96ccccc50eb6cb7de8ee6c0e06f2f4c1cda6e4c (diff)
Refactor configuration
-rw-r--r--config.php15
-rw-r--r--config.production.php34
2 files changed, 14 insertions, 35 deletions
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) {
diff --git a/config.production.php b/config.production.php
index 144cac5..b296813 100644
--- a/config.production.php
+++ b/config.production.php
@@ -1,36 +1,6 @@
<?php
-use Illuminate\Support\Str;
-use Carbon\Carbon;
-
-$now = Carbon::now();
-
return [
- 'baseUrl' => 'https://www.davidtsadler.com',
- 'production' => true,
-
- 'collections' => [
- 'posts' => [
- // Default author, if not provided in a post
- 'author' => 'David T. Sadler',
- 'sort' => '-date',
- 'path' => '/posts',
- '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}',
- 'posts' => function ($page, $allPosts) {
- return $allPosts->filter(function ($post) use ($page) {
- $tagSlugs = array_map(function ($tag) {
- return Str::slug($tag);
- }, $post->tags);
- return $post->tags ? in_array($page->getFilename(), $tagSlugs, true) : false;
- });
- },
- ],
- ],
+ 'baseUrl' => 'https://www.davidtsadler.com',
+ 'production' => true,
];