{
  "$schema": "./.schemas/page.schema.json",
  "title": "Reading list",
  "icon": "book",
  "sources": {
    "reading": {
      "url": "https://api.notion.com",
      "secret": "notion",
      "every": "5m",
      "headers": {
        "Notion-Version": "2026-03-11"
      },
      "requests": {
        "now": {
          "path": "/v1/data_sources/5d2e9b14-8a37-4c6f-b1e0-3f9a6c2d7e85/query",
          "method": "POST",
          "body": {
            "filter": {
              "property": "Status",
              "status": {
                "equals": "In progress"
              }
            },
            "sorts": [
              {
                "timestamp": "last_edited_time",
                "direction": "descending"
              }
            ],
            "page_size": 20
          }
        },
        "next": {
          "path": "/v1/data_sources/5d2e9b14-8a37-4c6f-b1e0-3f9a6c2d7e85/query",
          "method": "POST",
          "body": {
            "filter": {
              "property": "Status",
              "status": {
                "equals": "Not started"
              }
            },
            "sorts": [
              {
                "timestamp": "created_time",
                "direction": "ascending"
              }
            ],
            "page_size": 50
          }
        },
        "finished": {
          "path": "/v1/data_sources/5d2e9b14-8a37-4c6f-b1e0-3f9a6c2d7e85/query",
          "method": "POST",
          "body": {
            "filter": {
              "property": "Status",
              "status": {
                "equals": "Done"
              }
            },
            "sorts": [
              {
                "timestamp": "last_edited_time",
                "direction": "descending"
              }
            ],
            "page_size": 4
          }
        }
      },
      "derive": [
        {
          "name": "now_cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "now.has_more",
                  "equals": true
                },
                {
                  "path": "now.request_status.type",
                  "equals": "incomplete"
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "next_cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "next.has_more",
                  "equals": true
                },
                {
                  "path": "next.request_status.type",
                  "equals": "incomplete"
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "now_raw",
          "value": {
            "each": "now.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"
                }
              }
            }
          }
        },
        {
          "name": "now_titled",
          "value": {
            "each": "now_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "now_rows",
          "value": {
            "each": "now_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        },
        {
          "name": "next_raw",
          "value": {
            "each": "next.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"
                }
              }
            }
          }
        },
        {
          "name": "next_titled",
          "value": {
            "each": "next_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "next_rows",
          "value": {
            "each": "next_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        },
        {
          "name": "finished_raw",
          "value": {
            "each": "finished.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"
                }
              }
            }
          }
        },
        {
          "name": "finished_titled",
          "value": {
            "each": "finished_raw",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "title": {
                "join": "plain_text",
                "of": "pieces",
                "separator": ""
              }
            }
          }
        },
        {
          "name": "finished_rows",
          "value": {
            "each": "finished_titled",
            "fields": {
              "id": "id",
              "url": "url",
              "created": "created",
              "edited": "edited",
              "title": {
                "if": {
                  "all": [
                    {
                      "path": "title",
                      "exists": true
                    },
                    {
                      "path": "title",
                      "not": ""
                    }
                  ]
                },
                "then": "title",
                "else": {
                  "template": "Untitled"
                }
              }
            }
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "now",
      "type": "list",
      "label": "Reading",
      "items": [],
      "source": {
        "ref": "reading",
        "empty": {
          "text": "Nothing on the go.",
          "when": {
            "value": {
              "add": [
                {
                  "count": "now_rows",
                  "default": 0
                },
                0
              ]
            },
            "equals": 0
          }
        },
        "map": {
          "label": {
            "if": {
              "path": "now_cut",
              "equals": "yes"
            },
            "then": {
              "template": "Reading, 20 edited last"
            },
            "else": {
              "template": "Reading"
            }
          },
          "items": {
            "each": "now_rows",
            "limit": 20,
            "fields": {
              "key": "id",
              "icon": {
                "template": "book"
              },
              "text": "title",
              "detail": {
                "template": "{edited|ago}"
              },
              "url": "url"
            }
          }
        }
      },
      "row_actions": [
        {
          "label": "Finished",
          "icon": "checkmark",
          "method": "PATCH",
          "path": "/v1/pages/{id}",
          "body": {
            "properties": {
              "Status": {
                "status": {
                  "name": "Done"
                }
              }
            }
          },
          "error": "message"
        }
      ]
    },
    {
      "id": "next",
      "type": "list",
      "label": "Up next",
      "max_items": 7,
      "items": [],
      "source": {
        "ref": "reading",
        "empty": {
          "text": "Nothing waiting.",
          "when": {
            "value": {
              "add": [
                {
                  "count": "next_rows",
                  "default": 0
                },
                0
              ]
            },
            "equals": 0
          }
        },
        "map": {
          "label": {
            "if": {
              "path": "next_cut",
              "equals": "yes"
            },
            "then": {
              "template": "Up next, the 50 added first"
            },
            "else": {
              "template": "Up next"
            }
          },
          "items": {
            "each": "next_rows",
            "limit": 50,
            "fields": {
              "key": "id",
              "icon": {
                "template": "book.closed"
              },
              "text": "title",
              "detail": {
                "template": "Added {created|date}"
              },
              "url": "url"
            }
          }
        }
      },
      "row_actions": [
        {
          "label": "Start reading",
          "icon": "book",
          "method": "PATCH",
          "path": "/v1/pages/{id}",
          "body": {
            "properties": {
              "Status": {
                "status": {
                  "name": "In progress"
                }
              }
            }
          },
          "error": "message"
        }
      ]
    },
    {
      "id": "finished-heading",
      "type": "heading",
      "text": "Finished",
      "collapsed": true,
      "cards": [
        "finished"
      ]
    },
    {
      "id": "finished",
      "type": "list",
      "label": "Edited last",
      "max_items": 4,
      "items": [],
      "source": {
        "ref": "reading",
        "empty": {
          "text": "Nothing finished yet.",
          "when": {
            "value": {
              "add": [
                {
                  "count": "finished_rows",
                  "default": 0
                },
                0
              ]
            },
            "equals": 0
          }
        },
        "map": {
          "items": {
            "each": "finished_rows",
            "fields": {
              "key": "id",
              "icon": {
                "template": "checkmark.circle"
              },
              "text": "title",
              "detail": {
                "template": "{edited|ago}"
              },
              "url": "url"
            }
          }
        }
      }
    }
  ]
}
