I want to do a scheduled post.

I want to do a scheduled post.

I’m using gatsby.js, stradi and graphQL.
I am creating a blog.

I’d like to do a scheduled post, but
I don’t know how to do that.

Hey there!

If you’re using gatsby and the site is a blog, then i’m assuming all pages are statically generated (instead of fetching blog post content dynamically client-side, which isn’t good for SEO). Is this correct?

If so, I think you can achieve this by using cron tasks in Strapi. Something like what’s described here:

  1. Enable the publish/draft feature for your posts collection.
  2. Add a datetime field called scheduled_at to your Posts collection.
  3. Configure a cron task to run periodically that checks your posts collection for posts that are published and where the scheduled_at is less than or equal the current datetime. e.g.:
const postsToPublish = await strapi.services.post.find({ published_at_null: false, scheduled_at_lte: new Date() });

if (postsToPublish?.length > 0) {
    await triggerGatsbyBuildWebhook()
}

This is one way of doing it. The other way is to use Strapi’s built-in webhook feature in the Admin UI, however it’s a bit limited out-of-the-box in terms of controlling when the webhook is triggered.

1 Like

By the way, we’ve just updated this guide to Strapi v4. :nerd_face: