getkirby / ideas

This is the backlog of ideas and feature requests from the last two years. Use our new feedback platform to post your new ideas or vote on existing ideas.
https://feedback.getkirby.com
20 stars 0 forks source link

Content: schedule publication #291

Open neildaniels opened 5 years ago

neildaniels commented 5 years ago

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:

  1. 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.

  2. A more elaborate scheduling system that takes takes an arbitrary number of dates. Basically a list of date ranges

  3. Something more calendar-based, like "every Friday, for 10 hours, starting at 10am", "first Tuesday of the month", "2nd day of the month"

neildaniels commented 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".

Setup

Page Blueprint

title: Blog Post

num: '{{ page.created.toDate("YmdHi") }}'

fields:
  created:
    label: Published Date
    type: date
    time:
      step: 1
      notation: 12

Page Model

public function isListed(): bool {
    return parent::isListed() && ($this->created() == '' || time() >= $this->created()->toDate());
}

public function isScheduledPost(): bool {
    return parent::isListed() && !$this->isListed();
}

Quirks

  1. Because we're overriding 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".
    • In this case, this is where the panel should handle changing the statuses more cleverly to know that "Scheduled" should be shown instead of just "Listed".
  2. 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):

    • Not sure of a great way Kirby could do this in a more generic way, other than saying if any page on the site is future-dated.
      
      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.

HashandSalt commented 5 years ago

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