#let get_figures(body) = {
  if type(body) == array {
    body.map(get_figures).flatten()
  } else if type(body) == dictionary {
    body.values().map(get_figures).flatten()
  } else if type(body) != content {
    ()
  }else if body.func() == figure {
    (body,)
  } else {
    body.fields().values().map(get_figures).flatten()
  }
}

#let main = include("../main.typ")
#let figures = {
  let figures = (:)
  for fig in get_figures(main) {
    let fields = fig.fields()
    assert("label" in fields, message: "no 'label' in " + repr(fields))
    let lab = fields.remove("label")
    let body = fields.remove("body")
    figures.insert(str(lab), figure(..fields, body))
  }
  figures
}

#let get_figure(label) = {
  figures.at(str(label))
}
