👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

Issue with the Sanity calendar plugin not displaying the schedule button, but resolved with help from another user.

17 replies
Last updated: Jan 28, 2022
Hello Sanity people, do you have any experience with the https://www.sanity.io/blog/calendar-plugin ? I can’t make it work, the schedule button does not show even though I’ve added my document in the content-calendar.json:

{
  "types": [
    {
      "type": "homePage",
      "field": "publishedAt"
    }
  ]
}
Does anyone know what could be wrong here?
🤔
homePage
is the name of my custom document
Jan 27, 2022, 12:48 PM
I haven’t personally had the opportunity to use this plugin from scratch yet - so great learning opportunity for me, and I’m wondering if there are some assumptions in the referenced document schemas that aren’t clearly defined. My custom document type name in my case is just
article
. I have tried to display off of both a basic date type field named
publishedAt
and the default
_createdAt
field id with no luck yet, though I have only just spent a few minutes with it. If this detail is in the documentation, I glazed right over it too!
here is my content-calendar config on first pass (this is NOT working yet for me either)

{
  "types": [
    {
      "type": "article",
      "field": "publishedAt",
      "titleField": "title"
    }
  ],
  "calendar": {
    "event": {
      "dateFormat": "MMMM, dd yyyy",
      "timeFormat": "hh:mm a",
      "showAuthor": "false"
    }
  },
  "filterWarnings": [{}]
}
And here is the first bit of my example
article
document:
export default {
  name: 'article',
  title: 'Article',
  type: 'document',
  icon: GiBeech,
  fields: [
    {
      name: 'title',
      title: 'Title',
      type: 'string',
    },
    {
      name: 'slug',
      title: 'Slug',
      type: 'slug',
      options: {
        source: 'title',
        maxLength: 96
      }
    },
    {
      name: 'publishedAt',
      title: 'Published Date',
      type: 'date'
    }, //...
I think I have this running in a different community example schema. I’ll dig into that next to compare.
Jan 27, 2022, 6:25 PM
the git documentation is here if you haven’t seen it yet: https://github.com/sanity-io/sanity-plugin-content-calendar
Jan 27, 2022, 6:25 PM
okay, I got it to work in my barebones from scratch build - now let’s see if we can get yours going.I think this is the end result you’re looking for:
Jan 27, 2022, 6:44 PM
here is my studio document:
Jan 27, 2022, 6:45 PM
(I am currently in NA Pacific time)
Jan 27, 2022, 6:46 PM
./config/content-calendar.json

{
  "types": [
    {
      "type": "article",
      "field": "publishedAt",
      "titleField": "title"
    }
  ],
  "calendar": {
    "event": {
      "dateFormat": "MMMM, dd yyyy",
      "timeFormat": "hh:mm a",
      "showAuthor": "false"
    }
  },
  "filterWarnings": [{}]
}
my article document schema:

export default {
  name: 'article',
  title: 'Article',
  type: 'document',
    fields: [
    {
      name: 'title',
      title: 'Title',
      type: 'string',
    },
    {
      // TODO: import slugify fn -- do I want this to be legible?
      name: 'slug',
      title: 'Slug',
      type: 'slug',
      options: {
        source: 'title',
        maxLength: 96
      }
    },
    {
      name: 'publishedAt',     /* <<< the important bit */
      title: 'Published at',
      type: 'datetime'
    },
// continued...
Jan 27, 2022, 6:48 PM
I’m not sure if it’s buggy or if there is something that I can proactively do to get these to display. But existing documents aren’t displaying for me in the behind-the-scenes query that the plugin does. I had to create a new document and set publishedAt type
datetime
to get it to display.
Let’s see if you can get to where I am and work from there.
Jan 27, 2022, 6:51 PM
actually, any new documents set to a passed published date aren’t appearing either - I’ll tinker with it some more to see if I can get this to work
Jan 27, 2022, 6:52 PM
actually, any new documents set to a passed published date aren’t appearing either - I’ll tinker with it some more to see if I can get this to work
Jan 27, 2022, 6:52 PM
please let us know if you can see the schedule updates in your document publish button with my example
I’ve asked our app support team if I’m missing a flag to display past-published documents in this case, as it appears the example shows that this is expected.
Jan 27, 2022, 7:17 PM
Omg thank you for all this work, I'll check it first thing tomorrow, I'll keep you updated, you're the best 👏
Jan 27, 2022, 7:19 PM
still tinkering some, now that my example future-published article is in the past, it continues to display in the calendar. I’ll try to update if I get any more feedback.
Jan 27, 2022, 8:02 PM
I think that’s normal tho, I belive you need some backend cronjob

Performing the publish event, in the future
This plugin does not perform the publishing of documents on its own, as it is just a Studio plugin running in an editors' browser. In order to actually perform the scheduled publishing, a script needs to run either periodically, or at the given publishing times to perform the publish action.

We advise setting up a cronjob running for instance every minute that checks if any document should be published and then perform that action. A full script that does this is represented below.

When the publish event eventually occurs, any newer draft will be discarded. This is why the plugin warns you if you make further changes to a document after you schedule it. If you don't want to lose the newer changes an editor will need to Reschedule them. The plugin will prompt for this with a warning in the calendar view and an updated document action.
Jan 27, 2022, 8:06 PM
Jan 27, 2022, 8:06 PM
ah right, I haven’t gone that far in my tests yet. I’ll try building this into my next project!
Jan 27, 2022, 8:07 PM
awesome you rock 🙌
Jan 27, 2022, 8:08 PM
Ok things are way more clear now, I didn’t know I had to set a date later on the
PublishedAt
field. When I change this to a later date, I see the
schedule
button finally! So it seems like it’s all working well after all 😊Thanks a lot for your help Julia
Jan 28, 2022, 8:37 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?