{
  "$schema": "./.schemas/page.schema.json",
  "title": "Content calendar",
  "icon": "calendar",
  "sources": {
    "calendar": {
      "url": "https://api.notion.com",
      "secret": "notion",
      "every": "5m",
      "headers": {
        "Notion-Version": "2026-03-11"
      },
      "requests": {
        "late": {
          "path": "/v1/data_sources/9a6b3c1d-2e4f-4a58-8b7c-6d1e0f2a3b49/query",
          "method": "POST",
          "body": {
            "filter": {
              "and": [
                {
                  "property": "Status",
                  "status": {
                    "does_not_equal": "Published"
                  }
                },
                {
                  "property": "Publish date",
                  "date": {
                    "before": "{date.today}"
                  }
                }
              ]
            },
            "sorts": [
              {
                "property": "Publish date",
                "direction": "ascending"
              }
            ],
            "page_size": 20
          }
        },
        "coming": {
          "path": "/v1/data_sources/9a6b3c1d-2e4f-4a58-8b7c-6d1e0f2a3b49/query",
          "method": "POST",
          "body": {
            "filter": {
              "and": [
                {
                  "property": "Status",
                  "status": {
                    "does_not_equal": "Published"
                  }
                },
                {
                  "property": "Publish date",
                  "date": {
                    "on_or_after": "{date.today}"
                  }
                },
                {
                  "property": "Publish date",
                  "date": {
                    "on_or_before": "{date.days_ahead_13}"
                  }
                }
              ]
            },
            "sorts": [
              {
                "property": "Publish date",
                "direction": "ascending"
              }
            ],
            "page_size": 60
          }
        },
        "published": {
          "path": "/v1/data_sources/9a6b3c1d-2e4f-4a58-8b7c-6d1e0f2a3b49/query",
          "method": "POST",
          "body": {
            "filter": {
              "property": "Status",
              "status": {
                "equals": "Published"
              }
            },
            "sorts": [
              {
                "property": "Publish date",
                "direction": "descending"
              }
            ],
            "page_size": 4
          }
        }
      },
      "derive": [
        {
          "name": "late_cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "late.has_more",
                  "equals": true
                },
                {
                  "path": "late.request_status.type",
                  "equals": "incomplete"
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "coming_cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "coming.has_more",
                  "equals": true
                },
                {
                  "path": "coming.request_status.type",
                  "equals": "incomplete"
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "late_raw",
          "value": {
            "each": "late.results",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created_time",
              "edited": "last_edited_time",
              "pieces": {
                "first": "value.title",
                "of": "properties",
                "entries": true,
                "where": {
                  "path": "value.type",
                  "equals": "title"
                }
              },
              "start": {
                "path": "properties[\"Publish date\"].date.start"
              },
              "end": {
                "path": "properties[\"Publish date\"].date.end"
              },
              "status": {
                "path": "properties[\"Status\"].status.name",
                "default": ""
              }
            }
          }
        },
        {
          "name": "late_titled",
          "value": {
            "each": "late_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "start": "start",
              "end": "end",
              "status": "status",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "late_rows",
          "value": {
            "each": "late_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "start": "start",
              "end": "end",
              "status": "status",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        },
        {
          "name": "coming_raw",
          "value": {
            "each": "coming.results",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created_time",
              "edited": "last_edited_time",
              "pieces": {
                "first": "value.title",
                "of": "properties",
                "entries": true,
                "where": {
                  "path": "value.type",
                  "equals": "title"
                }
              },
              "start": {
                "path": "properties[\"Publish date\"].date.start"
              },
              "end": {
                "path": "properties[\"Publish date\"].date.end"
              },
              "status": {
                "path": "properties[\"Status\"].status.name",
                "default": ""
              }
            }
          }
        },
        {
          "name": "coming_titled",
          "value": {
            "each": "coming_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "start": "start",
              "end": "end",
              "status": "status",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "coming_rows",
          "value": {
            "each": "coming_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "start": "start",
              "end": "end",
              "status": "status",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        },
        {
          "name": "published_raw",
          "value": {
            "each": "published.results",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created_time",
              "edited": "last_edited_time",
              "pieces": {
                "first": "value.title",
                "of": "properties",
                "entries": true,
                "where": {
                  "path": "value.type",
                  "equals": "title"
                }
              },
              "start": {
                "path": "properties[\"Publish date\"].date.start"
              },
              "end": {
                "path": "properties[\"Publish date\"].date.end"
              },
              "status": {
                "path": "properties[\"Status\"].status.name",
                "default": ""
              }
            }
          }
        },
        {
          "name": "published_titled",
          "value": {
            "each": "published_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "start": "start",
              "end": "end",
              "status": "status",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "published_rows",
          "value": {
            "each": "published_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "start": "start",
              "end": "end",
              "status": "status",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "late",
      "type": "list",
      "label": "Past its date",
      "items": [],
      "source": {
        "ref": "calendar",
        "when": {
          "value": {
            "add": [
              {
                "count": "late_rows",
                "default": 0
              },
              0
            ]
          },
          "gt": 0
        },
        "map": {
          "label": {
            "if": {
              "path": "late_cut",
              "equals": "yes"
            },
            "then": {
              "template": "Past its date, the 20 oldest"
            },
            "else": {
              "template": "Past its date"
            }
          },
          "items": {
            "each": "late_rows",
            "limit": 20,
            "fields": {
              "key": "id",
              "icon": {
                "template": "calendar"
              },
              "text": "title",
              "subtitle": "status",
              "detail": {
                "template": "{start|day}"
              },
              "url": "url"
            }
          }
        }
      }
    },
    {
      "id": "coming",
      "type": "agenda",
      "label": "Next 14 days",
      "days": 14,
      "hide_empty_days": true,
      "hide_all_day_label": true,
      "max_events": 7,
      "items": [],
      "source": {
        "ref": "calendar",
        "map": {
          "label": {
            "if": {
              "path": "coming_cut",
              "equals": "yes"
            },
            "then": {
              "template": "Next 14 days, the first 60"
            },
            "else": {
              "template": "Next 14 days"
            }
          },
          "items": {
            "each": "coming_rows",
            "limit": 60,
            "fields": {
              "title": "title",
              "start": "start",
              "end": "end",
              "detail": "status",
              "url": "url"
            }
          }
        }
      }
    },
    {
      "id": "published-heading",
      "type": "heading",
      "text": "Recently published",
      "collapsed": true,
      "cards": [
        "published"
      ]
    },
    {
      "id": "published",
      "type": "list",
      "label": "By publish date",
      "max_items": 4,
      "items": [],
      "source": {
        "ref": "calendar",
        "empty": {
          "text": "Nothing published yet.",
          "when": {
            "value": {
              "add": [
                {
                  "count": "published_rows",
                  "default": 0
                },
                0
              ]
            },
            "equals": 0
          }
        },
        "map": {
          "items": {
            "each": "published_rows",
            "fields": {
              "key": "id",
              "icon": {
                "template": "checkmark.circle"
              },
              "text": "title",
              "detail": {
                "template": "{start|day}"
              },
              "url": "url"
            }
          }
        }
      }
    }
  ]
}
