summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2020-05-25 23:17:49 +0100
committerDavid T. Sadler <davidtsadler@googlemail.com>2020-05-25 23:17:49 +0100
commitfb37d65e2c58504d089b4de73ca63f127f9d40f1 (patch)
treeda3358fcbe83fecd4e511007d051ca64014756e1 /source
parentce98857fc5d4014c74041400f66521fc024e8d94 (diff)
Add Scheduling Posts in Jigsaw
Diffstat (limited to 'source')
-rw-r--r--source/_posts/scheduling_posts_in_jigsaw.md37
1 files changed, 37 insertions, 0 deletions
diff --git a/source/_posts/scheduling_posts_in_jigsaw.md b/source/_posts/scheduling_posts_in_jigsaw.md
new file mode 100644
index 0000000..43ba071
--- /dev/null
+++ b/source/_posts/scheduling_posts_in_jigsaw.md
@@ -0,0 +1,37 @@
+---
+extends: _layouts.post
+section: content
+title: Scheduling Posts in Jigsaw
+date: 2020-06-01
+description: How I use Jigsaw's filtering to schedule future posts.
+tags: [Jigsaw]
+---
+
+[Jigsaw](https://jigsaw.tighten.co) is a static site generator that I use for my site and one of its features is the ability to create a [filter](https://jigsaw.tighten.co/docs/collections-filtering) that determines which items in a collection will be included in the final build.
+
+It works by you adding a *filter* key to a collection's array in your *config.php* file, and specifying a callable that accepts an item from the collection and that returns a boolean. By returning false an item will not be built.
+
+Below is how I have setup my *config.production.php* file which is used when building the site for deployment.
+
+```php
+<?php
+
+use Carbon\Carbon;
+
+return [
+ 'collections' => [
+ 'posts' => [
+ 'filter' => function ($item) {
+ $date = $item->date ? Carbon::createFromFormat('U', $item->date) : null;
+ // Only publish posts that have a date and which is not in the future.
+ return $date ? $date <= Carbon::now() : false;
+ }
+ ],
+ ],
+];
+```
+
+When deploying the site each post is passed to this filter. The first thing it does is convert the date that has been specified in the post's YAML front matter into a [Carbon](https://carbon.nesbot.com/) instance. It then returns true if the date is on or before the current date, I.e. when the site is been deployed.
+
+With this filter I can specify future dates for several posts and they will only published once that date comes around. Posts are also exluded if a date has not been specified. This allows me to have posts that are a work in progress and shouldn't be published.
+