summaryrefslogtreecommitdiff
path: root/gemini/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.gmi
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2021-05-17 15:59:24 +0100
committerDavid T. Sadler <davidtsadler@googlemail.com>2021-05-17 15:59:24 +0100
commitbbf7974715b9a43bab207df75ef69209cdf13850 (patch)
tree13078ed02a7fec8f28b1d6046e6533f1be2aec54 /gemini/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.gmi
parent3e9a949c823917e0f4189628959fa4d3eb908db4 (diff)
Move to building localy rather than on remote server
Diffstat (limited to 'gemini/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.gmi')
-rw-r--r--gemini/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.gmi49
1 files changed, 49 insertions, 0 deletions
diff --git a/gemini/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.gmi b/gemini/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.gmi
new file mode 100644
index 0000000..1d4c064
--- /dev/null
+++ b/gemini/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.gmi
@@ -0,0 +1,49 @@
+# Scheduling Posts in Jigsaw
+
+> Mon 1st June 2020 By David T. Sadler.
+
+Jigsaw is a static site generator that I use for my site and one of its features is the ability to create a filter 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 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.
+
+### Links
+
+=> https://jigsaw.tighten.co/ Jigsaw - Static Site Generator for PHP Developers.
+=> https://jigsaw.tighten.co/docs/collections-filtering/ Using Filters in Jigsaw.
+=> https://carbon.nesbot.com/ Carbon - PHP API Extension for DateTime.
+
+=> /posts/jigsaw/ Jigsaw - Read More Posts.
+
+I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.
+
+=> mailto:david@davidtsadler.com Email david@davidtsadler.com
+
+=> https://creativecommons.org/licenses/by-sa/4.0/ The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
+
+Copyright © 2021 David T. Sadler.
+
+=> / Return to Homepage.