165 lines
8.9 KiB
Plaintext
165 lines
8.9 KiB
Plaintext
#let report-file = sys.inputs.at("report")
|
|
#let report-format = sys.inputs.at("format")
|
|
#let report = if report-format == "json" { json(report-file) } else { yaml(report-file) }
|
|
#assert(type(report) == dictionary, message: "report must be an object")
|
|
#assert(report.at("schema_version", default: none) == 1, message: "unsupported or missing schema_version")
|
|
#assert(type(report.at("title", default: none)) == str and report.title.trim() != "", message: "title must be a non-empty string")
|
|
#assert(type(report.at("metadata", default: none)) == dictionary, message: "metadata must be an object")
|
|
#assert(type(report.metadata.at("Date", default: none)) == str and report.metadata.Date != "", message: "metadata.Date is required")
|
|
#assert(type(report.metadata.at("Author", default: none)) == str and report.metadata.Author != "", message: "metadata.Author is required")
|
|
#let get(data, key, default: none) = data.at(key, default: default)
|
|
#let branding = get(report, "branding", default: (:))
|
|
#let theme-choice = get(branding, "theme", default: (:))
|
|
#let theme = if theme-choice == "default" { (:) } else if theme-choice == "teal" { (
|
|
ink: "#17212b", muted: "#526777", line: "#b9d8df", paper_soft: "#eef7f8",
|
|
accent: "#086f83", info: "#007f95", warning: "#a86712",
|
|
critical: "#a12e4b", success: "#19765b",
|
|
) } else { theme-choice }
|
|
#let color(key, fallback) = rgb(str(get(theme, key, default: fallback)))
|
|
#let ink = color("ink", "#22262b")
|
|
#let muted = color("muted", "#66707a")
|
|
#let line-color = color("line", "#d7dce1")
|
|
#let soft = color("paper_soft", "#f5f7f8")
|
|
#let accent = color("accent", "#34495e")
|
|
#let severity-color(value) = if value == "critical" { color("critical", "#7a3030")
|
|
} else if value in ("warning", "high", "medium") { color("warning", "#8a671c")
|
|
} else if value in ("ok", "success") { color("success", "#356344")
|
|
} else { color("info", "#385f7a") }
|
|
#let as-text(value) = str(value)
|
|
#let inline-code(value) = {
|
|
let parts = str(value).split("`")
|
|
if parts.len() == 1 or calc.rem(parts.len(), 2) == 0 { return str(value) }
|
|
let result = ()
|
|
for (index, part) in parts.enumerate() {
|
|
result.push(if calc.rem(index, 2) == 1 { raw(part, block: false) } else { text(part) })
|
|
}
|
|
result.join()
|
|
}
|
|
#let report-type-label(value) = if value == "technical" { "Technical report"
|
|
} else if value == "briefing" { "Stakeholder briefing" } else { str(value) }
|
|
#let heading(title) = block(above: 12pt, below: 5pt)[
|
|
#text(size: 13pt, weight: "bold", fill: accent)[#as-text(title)]
|
|
#line(length: 100%, stroke: 0.6pt + line-color)
|
|
]
|
|
#let badge(value) = box(inset: (x: 5pt, y: 2pt), radius: 2pt,
|
|
fill: severity-color(str(value)).lighten(85%),
|
|
stroke: 0.5pt + severity-color(str(value)))[
|
|
#text(size: 7.5pt, weight: "bold", fill: severity-color(str(value)))[#upper(as-text(value))]
|
|
]
|
|
#let callout(body, kind: "info", title: none) = block(width: 100%, inset: 8pt,
|
|
fill: severity-color(kind).lighten(92%), stroke: (left: 2pt + severity-color(kind)))[
|
|
#if title != none { text(weight: "bold", fill: severity-color(kind))[#as-text(title)]; parbreak() }
|
|
#body
|
|
]
|
|
#let render-block(item) = {
|
|
let kind = get(item, "type", default: "text")
|
|
if kind == "text" { inline-code(get(item, "text", default: "")) }
|
|
else if kind == "bullets" { list(..get(item, "items", default: ()).map(value => [#as-text(value)])) }
|
|
else if kind == "steps" { enum(..get(item, "items", default: ()).map(value => [#as-text(value)])) }
|
|
else if kind == "callout" { callout([#as-text(get(item, "text", default: ""))],
|
|
kind: get(item, "kind", default: "info"), title: get(item, "title", default: none)) }
|
|
else if kind == "code" { block(width: 100%, inset: 7pt, fill: soft,
|
|
stroke: 0.5pt + line-color)[#text(font: get(theme, "mono_font", default: "DejaVu Sans Mono"),
|
|
size: 8pt)[#as-text(get(item, "text", default: ""))]] }
|
|
else if kind == "subsection" {
|
|
block(above: 5pt, below: 3pt)[#text(weight: "bold", fill: ink)[#as-text(get(item, "title", default: ""))]]
|
|
for child in get(item, "content", default: ()) { render-block(child); v(3pt) }
|
|
}
|
|
else if kind == "card" {
|
|
let tone = get(item, "tone", default: none)
|
|
let border = if tone == none { line-color } else { severity-color(tone) }
|
|
let background = if tone == none { soft } else { border.lighten(93%) }
|
|
block(width: 100%, inset: 9pt, radius: 3pt, below: 6pt,
|
|
fill: background, stroke: 0.6pt + border)[
|
|
#text(weight: "bold", fill: if tone == none { accent } else { border })[#as-text(item.title)]
|
|
#parbreak()
|
|
#for child in item.content { render-block(child); v(3pt) }
|
|
]
|
|
}
|
|
}
|
|
#let logo = get(branding, "logo", default: none)
|
|
#let organization = get(branding, "organization", default: "Report")
|
|
#set page(paper: "a4", margin: (top: 20mm, bottom: 18mm, x: 20mm),
|
|
header: context {
|
|
grid(columns: (1fr, auto), align: (left, right + horizon),
|
|
text(size: 7.5pt, weight: "bold", fill: muted)[#as-text(organization)#if "report_type" in report { [ — #report-type-label(report.report_type)] }],
|
|
if logo != none { image(logo, height: 8mm, fit: "contain") })
|
|
v(3pt); line(length: 100%, stroke: 0.5pt + line-color)
|
|
},
|
|
footer: context grid(columns: (1fr, auto),
|
|
text(size: 7pt, fill: muted)[#if "id" in report { [Report #as-text(report.id)] }],
|
|
text(size: 7pt, fill: muted)[Page #counter(page).display()]))
|
|
#set text(font: get(theme, "font", default: "DejaVu Sans"), size: 9.5pt, fill: ink)
|
|
#set par(leading: 0.58em, spacing: 0.55em)
|
|
#show raw.where(block: false): box.with(
|
|
fill: soft, stroke: 0.5pt + line-color, radius: 3pt,
|
|
inset: (x: 4pt, y: 1pt), outset: (y: 1pt),
|
|
)
|
|
|
|
#text(size: 22pt, weight: "bold", fill: accent)[#as-text(report.title)]
|
|
#if "subtitle" in report { v(3pt); text(size: 11pt, fill: muted)[#as-text(report.subtitle)] }
|
|
#if "report_type" in report or "status" in report or "severity" in report {
|
|
v(7pt)
|
|
for value in (get(report, "report_type"), get(report, "status"), get(report, "severity")) {
|
|
if value != none { badge(if value == get(report, "report_type") { report-type-label(value) } else { value }); h(4pt) }
|
|
}
|
|
}
|
|
#v(10pt)
|
|
#block(width: 100%, inset: 8pt, fill: soft, stroke: 0.5pt + line-color)[
|
|
#grid(columns: (1fr, 1fr), row-gutter: 5pt, column-gutter: 10pt,
|
|
..report.metadata.pairs().map(pair => [#text(size: 7.5pt, fill: muted)[#pair.at(0)]\
|
|
#as-text(pair.at(1))]))
|
|
]
|
|
#if "summary" in report { heading("Executive summary"); callout([#as-text(report.summary)]) }
|
|
#if "metrics" in report and report.metrics.len() > 0 {
|
|
v(7pt)
|
|
grid(columns: (1fr,) * report.metrics.len(), gutter: 5pt,
|
|
..report.metrics.map(metric => {
|
|
let tone = severity-color(get(metric, "tone", default: "info"))
|
|
block(width: 100%, inset: 7pt, radius: 2pt, fill: tone.lighten(92%), stroke: 0.5pt + tone)[
|
|
#text(size: 7.5pt, weight: "bold", fill: muted)[#upper(as-text(metric.label))]
|
|
#parbreak()
|
|
#text(size: 16pt, weight: "bold", fill: tone)[#as-text(metric.value)]
|
|
]
|
|
}))
|
|
}
|
|
#if "timeline" in report and report.timeline.len() > 0 {
|
|
heading("Timeline")
|
|
table(columns: (31mm, 1.1fr, 2fr), inset: 5pt, stroke: 0.45pt + line-color,
|
|
fill: (x, y) => if y == 0 { soft } else { none }, align: (left, left, left),
|
|
table.header([Time], [Event], [Notes]),
|
|
..report.timeline.map(entry => (
|
|
[#text(size: 8pt)[#as-text(entry.time)]],
|
|
[#as-text(entry.event)],
|
|
[#as-text(get(entry, "notes", default: ""))],
|
|
)).flatten())
|
|
}
|
|
#if "findings" in report and report.findings.len() > 0 {
|
|
heading("Findings")
|
|
for finding in report.findings { block(width: 100%, inset: 8pt, below: 6pt, breakable: false,
|
|
stroke: 0.5pt + line-color, radius: 2pt)[
|
|
#grid(columns: (1fr, auto, auto), gutter: 5pt, align: (left, center, center),
|
|
text(weight: "bold")[#as-text(finding.title)],
|
|
if "severity" in finding { badge(finding.severity) } else { [] },
|
|
if "status" in finding { badge(finding.status) } else { [] })
|
|
#if "evidence" in finding { parbreak(); text(size: 8pt, weight: "bold", fill: muted)[EVIDENCE]; parbreak(); as-text(finding.evidence) }
|
|
#if "assessment" in finding { parbreak(); text(size: 8pt, weight: "bold", fill: muted)[ASSESSMENT]; parbreak(); as-text(finding.assessment) }
|
|
] }
|
|
}
|
|
#for section in get(report, "sections", default: ()) {
|
|
heading(section.title)
|
|
for item in section.content { render-block(item); v(4pt) }
|
|
}
|
|
#if "actions" in report and report.actions.len() > 0 {
|
|
heading(get(report, "actions_title", default: "Action plan"))
|
|
for action in report.actions { block(below: 5pt)[#text(weight: "bold")[#as-text(action.title)]
|
|
#if "status" in action { h(5pt); badge(action.status) }
|
|
#if "text" in action { parbreak(); as-text(action.text) }
|
|
#for command in get(action, "commands", default: ()) { parbreak(); render-block((type: "code", text: command)) }] }
|
|
}
|
|
#if "closing" in report { heading("Current state"); callout([#as-text(report.closing)], title: "Stopping point") }
|
|
#for section in get(report, "appendices", default: ()) {
|
|
pagebreak(weak: true); heading(section.title)
|
|
for item in section.content { render-block(item); v(4pt) }
|
|
}
|