blob: 13a344c83a7febb3e480d37b6b5b21d156cabe93 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">The Home of David T. Sadler - All Posts About Jigsaw</title>
<id>https://davidtsadler.com/posts/jigsaw/atom.xml</id>
<link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/jigsaw/"/>
<link rel="self" type="application/atom+xml" href="https://davidtsadler.com/posts/jigsaw/atom.xml"/>
<updated>2020-06-01T12:00:00Z</updated>
<entry>
<title type="text">Scheduling Posts in Jigsaw</title>
<id>https://davidtsadler.com/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/</id>
<link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/"/>
<author><name>David T. Sadler.</name></author>
<published>2020-06-01T12:00:00Z</published>
<updated>2020-06-01T12:00:00Z</updated>
<content type="html"><h1>Scheduling Posts in Jigsaw</h1><blockquote>Mon 1st June 2020 By David T. Sadler.</blockquote><p>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.</p><p>It works by you adding a filter key to a collection&#039;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.</p><p>Below is how I have setup my config.production.php file which is used when building the site for deployment.</p><pre><code class="php">&lt;?php
use Carbon\Carbon;
return [
&#039;collections&#039; =&gt; [
&#039;posts&#039; =&gt; [
&#039;filter&#039; =&gt; function ($item) {
$date = $item-&gt;date ? Carbon::createFromFormat(&#039;U&#039;, $item-&gt;date) : null;
// Only publish posts that have a date and which is not in the future.
return $date ? $date &lt;= Carbon::now() : false;
}
],
],
];</code></pre><p>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&#039;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. </p><p>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&#039;t be published.</p><h3>Links</h3><a href="https://jigsaw.tighten.co/">Jigsaw - Static Site Generator for PHP Developers.</a><a href="https://jigsaw.tighten.co/docs/collections-filtering/">Using Filters in Jigsaw.</a><a href="https://carbon.nesbot.com/">Carbon - PHP API Extension for DateTime.</a><a href="/posts/jigsaw/">Jigsaw - Read More Posts.</a><p>I don&#039;t have comments as I don&#039;t want to manage them. You can however contact me at the below address if you want to.</p><a href="mailto:david@davidtsadler.com">Email david@davidtsadler.com</a><h3>License</h3><a href="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.</a><p>Copyright © 2021 David T. Sadler.</p><a href="/">Return to Homepage.</a></content>
</entry>
</feed>
|