Open neildaniels opened 5 years ago
Here's a look at what we current do to achieve a simple "make a page go listed at a specific time".
title: Blog Post
num: '{{ page.created.toDate("YmdHi") }}'
fields:
created:
label: Published Date
type: date
time:
step: 1
notation: 12
public function isListed(): bool {
return parent::isListed() && ($this->created() == '' || time() >= $this->created()->toDate());
}
public function isScheduledPost(): bool {
return parent::isListed() && !$this->isListed();
}
isListed()
here, the Panel always shows a page as "Unlisted" when it's future-dated (but still has a num
assigned to it). Which is correct-ish, but confusing when a page is legitimately just "Unlisted" and should never become "Listed".
We use the Kirby caching system, and it simply doesn't know when pages are scheduled. For places that know they're showing scheduled pages, we add this to the page model (of the parent page):
public function isCacheable(): bool {
if (!parent::isCacheable()) {
return false;
}
foreach ($this->children()->flip() as $page) { if ($page->num() !== null) { return !$page->isScheduledPost(); } } return true; }
Right now, the caching is entirely disabled for a parent page until all scheduled posts are published. This is obviously not ideal; it should still be cached, but have a TTL on the cache to be until the next scheduled post is set to go live. There doesn't seem to be a clean way to override the duration of a pages
cache, so this isn't really feasible right now.
Whilst it would be nice to have this out of the box there is a plugin that can do it https://github.com/omz13/kirby3-suncyclepages
We sometimes want to future-date blog/news posts so they only become listed after a certain date/time. Our current implementation "works" but has a few odd quirks that would probably be handled better by proper support at the Kirby-level.
Feature Description
Expanded Feature Set
While my use is simple enough to just need a single date involved, I can easily anticipate use-cases that warrant more elaborate scheduling:
A "publish date" and an "unpublish date". Between those two times, a page would be listed. Outside that range, the page would unlisted. Example use: you have a page with various events, and you want to highlight only ones that currently happening.
A more elaborate scheduling system that takes takes an arbitrary number of dates. Basically a list of date ranges
Something more calendar-based, like "every Friday, for 10 hours, starting at 10am", "first Tuesday of the month", "2nd day of the month"