summaryrefslogtreecommitdiff
path: root/www/posts/jigsaw/atom.xml
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">&lt;h1&gt;Scheduling Posts in Jigsaw&lt;/h1&gt;&lt;blockquote&gt;Mon 1st June 2020 By David T. Sadler.&lt;/blockquote&gt;&lt;p&gt;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.&lt;/p&gt;&lt;p&gt;It works by you adding a filter key to a collection&amp;#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.&lt;/p&gt;&lt;p&gt;Below is how I have setup my config.production.php file which is used when building the site for deployment.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&amp;lt;?php

use Carbon\Carbon;

return [
    &amp;#039;collections&amp;#039; =&amp;gt; [
        &amp;#039;posts&amp;#039; =&amp;gt; [
            &amp;#039;filter&amp;#039; =&amp;gt; function ($item) {
                $date = $item-&amp;gt;date ? Carbon::createFromFormat(&amp;#039;U&amp;#039;, $item-&amp;gt;date) : null;
                // Only publish posts that have a date and which is not in the future.
                return $date ? $date &amp;lt;= Carbon::now() : false;
            }
        ],
    ],
];&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;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&amp;#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. &lt;/p&gt;&lt;p&gt;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&amp;#039;t be published.&lt;/p&gt;&lt;h3&gt;Links&lt;/h3&gt;&lt;a href=&quot;https://jigsaw.tighten.co/&quot;&gt;Jigsaw - Static Site Generator for PHP Developers.&lt;/a&gt;&lt;a href=&quot;https://jigsaw.tighten.co/docs/collections-filtering/&quot;&gt;Using Filters in Jigsaw.&lt;/a&gt;&lt;a href=&quot;https://carbon.nesbot.com/&quot;&gt;Carbon - PHP API Extension for DateTime.&lt;/a&gt;&lt;a href=&quot;/posts/jigsaw/&quot;&gt;Jigsaw - Read More Posts.&lt;/a&gt;&lt;p&gt;I don&amp;#039;t have comments as I don&amp;#039;t want to manage them. You can however contact me at the below address if you want to.&lt;/p&gt;&lt;a href=&quot;mailto:david@davidtsadler.com&quot;&gt;Email david@davidtsadler.com&lt;/a&gt;&lt;h3&gt;License&lt;/h3&gt;&lt;a href=&quot;https://creativecommons.org/licenses/by-sa/4.0/&quot;&gt;The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.&lt;/a&gt;&lt;p&gt;Copyright © 2021 David T. Sadler.&lt;/p&gt;&lt;a href=&quot;/&quot;&gt;Return to Homepage.&lt;/a&gt;</content>
</entry>
</feed>