68 lines
2.3 KiB
Plaintext
68 lines
2.3 KiB
Plaintext
#import "modules/model.typ": report-model
|
|
|
|
#let report-file = sys.inputs.at("report", default: none)
|
|
|
|
#if report-file == none {
|
|
panic(
|
|
"Missing report input.\n" +
|
|
"Usage: typst compile --input report=reports/foo.yaml report.typ foo.pdf"
|
|
)
|
|
}
|
|
|
|
#let report = if sys.inputs.at("format", default: "yaml") == "json" { json(report-file) } else { yaml(report-file) }
|
|
#let metadata = report.at("metadata", default: (:))
|
|
|
|
#if "Author" not in metadata or str.trim(str(metadata.at("Author", default: ""))) == "" {
|
|
panic(
|
|
"Missing required report field: metadata.Author.\n" +
|
|
"Add this to the report YAML:\n\n" +
|
|
"metadata:\n Author: \"Your name\""
|
|
)
|
|
}
|
|
|
|
#if "Date" not in metadata or str.trim(str(metadata.at("Date", default: ""))) == "" {
|
|
panic(
|
|
"Missing required report field: metadata.Date.\n" +
|
|
"Add this to the report YAML:\n\n" +
|
|
"metadata:\n Date: \"YYYY-MM-DD\""
|
|
)
|
|
}
|
|
|
|
// Catalog entries use English labels as keys; partial locales fall back to English.
|
|
#let locales = json("config/locales.json")
|
|
#let language = report.at("language", default: "en")
|
|
#if type(language) != str {
|
|
panic("Report language must be a string, for example language: fr")
|
|
}
|
|
#let language = lower(language)
|
|
#if language not in locales {
|
|
panic("Unknown report language: " + language + ". Available languages: " + locales.keys().join(", "))
|
|
}
|
|
#let messages = locales.at(language)
|
|
#if type(messages) != dictionary or messages.values().any(value => type(value) != str) {
|
|
panic("Report language catalog must map labels to strings: " + language)
|
|
}
|
|
#let translate(value) = messages.at(value, default: locales.en.at(value, default: value))
|
|
|
|
#let themes = yaml("config/themes.yaml")
|
|
#let theme-choice = report.at("theme", default: report.at("branding", default: (:)).at("theme", default: "default"))
|
|
#let theme-name = if type(theme-choice) == str { lower(theme-choice) } else { "custom" }
|
|
|
|
#if theme-name != "custom" and theme-name not in themes {
|
|
panic(
|
|
"Unknown report theme: \"" + theme-name + "\".\n" +
|
|
"Set theme to one of: " + themes.keys().join(", ") + ".\n" +
|
|
"Example: theme: default"
|
|
)
|
|
}
|
|
|
|
#let theme = if theme-name == "custom" { themes.default + theme-choice } else { themes.at(theme-name) }
|
|
|
|
#show: report-model.with(
|
|
report: report,
|
|
language: language,
|
|
t: translate,
|
|
theme: theme,
|
|
logo: "/assets/beffroi.png",
|
|
)
|