Advice on API for functions that can take different kind of arguments

Hi,
I’m working on a simple template system that uses bundles to produce a structured HTML website, and I would like some feedback on the API I chose. The main idea revolves around sections, that would take a source as input and produce an HTML file as an output. Sections can also have subsections and are simply defined as :

// path is the export path of the section
#let section(path, content, ..subsections) = (path: path, content: content, subsections: subsections.pos())

// Example use
#let section-tree = section("example.html", [Example section],
  section("subsection1.html", [Subsection 1]),
  section("subsection1.html", [Subsection 2]),
)

Then, you can pass the whole section-tree into a different function that would automatically resolve export paths for all the files. With the above example :

- /example.html
- /example/subsection1.html
- /example/subsection2.html

The main question I have is about the way to construct the section dictionary. Ultimately, I would like to provide two ways to define sections :

  • classic with content: section("example.html", [Example])
  • by passing a file path: section("file.typ") (would resolve to (path: "file.html", content: include "file.typ", subsections: ())

I thought about making two functions to construct the sections , for example in a section module :

section.from-file("file.typ")
section.from-content("example.html", [Example])

But by looking at functions from the standard library, and maybe some other packages I use, I can’t seem to find examples of objects having different constructors. It seems that the idiomatic way to do that is to have one constructor that can take many different kind of arguments, usually in the form of a dictionary. Maybe something like:

section((file: "file.typ"))
section((path: "example.html", content: [Example]))

But that seems a bit heavy and requires a lot of checks in the section function to verify which keys are in the dictionary, if there are missing keys… So I wonder what would be more idiomatic? Or maybe you have other ideas? i am new to scripting in typst…