{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hku.jacobshing.com/statics/schemas/v3.json",
  "title": "HKU Notes metadata v3",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "enum": [
        "https://hku.jacobshing.com/statics/schemas/v3.json",
        "../../site/docs/statics/schemas/v3.json"
      ]
    },
    "build": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "requires": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "executables": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "python": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            },
            "prepare": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/step"
              }
            },
            "finish": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/step"
              }
            },
            "outputs": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "minLength": 1,
                "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
              },
              "minProperties": 1
            },
            "type": {
              "const": "latex"
            },
            "root_file": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
            },
            "output_file": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
            },
            "engine": {
              "enum": [
                "pdflatex",
                "xelatex",
                "lualatex"
              ]
            },
            "shell_escape": {
              "type": "boolean"
            },
            "args": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "config_file": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
            },
            "source": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": {
                  "const": "git"
                },
                "url": {
                  "type": "string",
                  "minLength": 1
                },
                "revision": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{40}$"
                },
                "subdirectory": {
                  "type": "string",
                  "minLength": 1,
                  "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
                }
              },
              "required": [
                "type",
                "url",
                "revision"
              ]
            },
            "hash_ignore": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "description": "Gitignore-style source hashing exclusions. Document metadata is always hashed."
            },
            "cache": {
              "type": "boolean",
              "default": true,
              "description": "Reuse verified artifacts when the source fingerprint matches."
            }
          },
          "required": [
            "type"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "requires": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "executables": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "python": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            },
            "prepare": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/step"
              }
            },
            "finish": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/step"
              }
            },
            "outputs": {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "minLength": 1,
                "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
              },
              "minProperties": 1
            },
            "type": {
              "const": "custom"
            },
            "output_file": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
            },
            "steps": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/step"
              }
            },
            "source": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": {
                  "const": "git"
                },
                "url": {
                  "type": "string",
                  "minLength": 1
                },
                "revision": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{40}$"
                },
                "subdirectory": {
                  "type": "string",
                  "minLength": 1,
                  "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
                }
              },
              "required": [
                "type",
                "url",
                "revision"
              ]
            },
            "environment": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "os": {
                  "enum": [
                    "linux",
                    "darwin",
                    "windows"
                  ]
                },
                "architecture": {
                  "enum": [
                    "x86_64",
                    "arm64"
                  ]
                },
                "distribution": {
                  "type": "string",
                  "minLength": 1
                },
                "version": {
                  "type": "string",
                  "minLength": 1
                }
              }
            },
            "hash_ignore": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "description": "Gitignore-style source hashing exclusions. Document metadata is always hashed."
            },
            "cache": {
              "type": "boolean",
              "default": true,
              "description": "Reuse verified artifacts when the source fingerprint matches."
            }
          },
          "required": [
            "type",
            "output_file",
            "steps"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "type": {
              "const": "alias"
            },
            "target": {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9_.-]*$"
            }
          },
          "required": [
            "type",
            "target"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "type": {
              "const": "page"
            }
          },
          "required": [
            "type"
          ]
        }
      ]
    },
    "profiles": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "requires": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "executables": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "python": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          },
          "prepare": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/step"
            }
          },
          "finish": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/step"
            }
          },
          "outputs": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
            },
            "minProperties": 1
          },
          "root_file": {
            "type": "string",
            "minLength": 1,
            "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
          },
          "output_file": {
            "type": "string",
            "minLength": 1,
            "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
          },
          "engine": {
            "enum": [
              "pdflatex",
              "xelatex",
              "lualatex"
            ]
          },
          "shell_escape": {
            "type": "boolean"
          },
          "args": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "config_file": {
            "type": "string",
            "minLength": 1,
            "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
          },
          "hash_ignore": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Gitignore-style source hashing exclusions. Document metadata is always hashed."
          },
          "cache": {
            "type": "boolean",
            "default": true,
            "description": "Reuse verified artifacts when the source fingerprint matches."
          }
        }
      }
    },
    "static_site": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "description": {
          "type": "string",
          "description": "A short description of the target, used in the static site.",
          "default": "-"
        },
        "meta_description": {
          "type": "string",
          "description": "A short description of the target, used in the HTML meta tags for SEO purposes."
        },
        "custom_md_file": {
          "type": "string",
          "description": "A custom Markdown file whose content will be copied to the end of the static site page.",
          "default": ""
        },
        "document_status": {
          "type": "string",
          "description": "The status of the document, used in the static site.",
          "enum": [
            "sre",
            "wip",
            "lts",
            "abd",
            "fin",
            "obs",
            "unk"
          ],
          "default": "unk"
        },
        "pdf_viewer": {
          "type": "string",
          "description": "Where the PDF viewer should be displayed on the details page.",
          "enum": [
            "at_head",
            "at_footer",
            "at_tag",
            "hidden"
          ],
          "default": "at_head"
        },
        "buttons": {
          "description": "An array of button objects that define the buttons to be displayed on the static site.",
          "oneOf": [
            {
              "type": "null",
              "description": "If null, two default buttons (Download and View Source) will be created automatically."
            },
            {
              "type": "array",
              "description": "Array of button objects. Use an empty array [] to display no buttons.",
              "items": {
                "type": "object",
                "required": [
                  "text",
                  "href"
                ],
                "additionalProperties": false,
                "properties": {
                  "index": {
                    "type": "integer",
                    "description": "The index of the button in the array. Used to determine the order of buttons.",
                    "default": 0
                  },
                  "is_primary": {
                    "type": "boolean",
                    "description": "Whether the button is a primary button or not.",
                    "default": false
                  },
                  "text": {
                    "type": "string",
                    "description": "The text to be displayed on the button.",
                    "minLength": 1
                  },
                  "icon": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "The icon to be displayed on the button. Use null or omit for no icon.",
                    "default": null
                  },
                  "href": {
                    "type": "string",
                    "description": "The URL to be linked to when the button is clicked.",
                    "minLength": 1,
                    "format": "uri-reference"
                  },
                  "message": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "The message to be displayed when hovering over the button. Use null or omit for no hover message.",
                    "default": null
                  }
                }
              }
            }
          ]
        }
      }
    },
    "authors": {
      "type": "array",
      "description": "A list of authors for the target.",
      "items": {
        "type": "string",
        "pattern": "^(!)?(@unknown|@do_not_sort|[a-zA-Z0-9_]*)$"
      },
      "default": [
        "jacob_shing"
      ],
      "minItems": 1
    }
  },
  "required": [
    "$schema",
    "build"
  ],
  "$defs": {
    "step": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "type": {
              "const": "latex"
            },
            "inputs": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
              },
              "minItems": 1
            },
            "engine": {
              "enum": [
                "pdflatex",
                "xelatex",
                "lualatex"
              ]
            },
            "shell_escape": {
              "type": "boolean"
            },
            "args": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "required": [
            "type",
            "inputs"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "type": {
              "const": "wordcount"
            },
            "inputs": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
              },
              "minItems": 1
            },
            "output": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
            }
          },
          "required": [
            "type",
            "inputs",
            "output"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "type": {
              "const": "command"
            },
            "argv": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "minItems": 1
            },
            "cwd": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
            },
            "inputs": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
              },
              "minItems": 1
            },
            "outputs": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
              },
              "minItems": 1
            }
          },
          "required": [
            "type",
            "argv"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "type": {
              "const": "shell"
            },
            "interpreter": {
              "type": "string",
              "minLength": 1
            },
            "script": {
              "type": "string",
              "minLength": 1
            },
            "cwd": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
            },
            "inputs": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
              },
              "minItems": 1
            },
            "outputs": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
              },
              "minItems": 1
            }
          },
          "required": [
            "type",
            "interpreter",
            "script"
          ]
        }
      ]
    }
  }
}
