Split travel and product-test via explicit report-type templates.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-21 14:31:22 +03:30
parent 89fa657df8
commit c188a6387a
10 changed files with 55 additions and 10 deletions

View File

@@ -22,6 +22,8 @@ uv pip install --python .venv-pdf/bin/python weasyprint
## Quick start
Always render from this project root so `_quarto.yml` applies (RTL CSS, filters, PDF post-render):
```bash
quarto render examples/travel-report.qmd
quarto render examples/product-test.qmd
@@ -29,12 +31,32 @@ quarto render examples/product-test.qmd
Outputs land in `_output/` (HTML + PDF). PDF is produced by `scripts/html-to-pdf.py` in `project.post-render`.
## Report types
## Templates
| Type | Example | Notes |
| --- | --- | --- |
| Travel / mission | `examples/travel-report.qmd` | Set `purpose` (and usually `destinations`, `report-date`) so the PDF title block shows travel meta (مقصد، هدف مأموریت، تیم، تاریخ). |
| Product / raw-material test | `examples/product-test.qmd` | Omit `purpose`. Put general info, samples, formula, and results in the body as Markdown tables (ported from Typst helpers in `typst-templates`). `destinations` is optional sidebar text. |
Two named metadata templates (Typst-style explicit choice). Pick one via `metadata-files` in the `.qmd` frontmatter — that sets `report-type` and controls whether the travel meta block is injected. Document type is **not** inferred from `purpose`.
| Template | File | `report-type` | Example |
| --- | --- | --- | --- |
| Travel / mission | `templates/travel.yml` | `travel` | `examples/travel-report.qmd` |
| Product / raw-material test | `templates/product-test.yml` | `product-test` | `examples/product-test.qmd` |
### Start a new report
1. Copy the matching example `.qmd` (keep its `metadata-files` line pointing at `templates/travel.yml` or `templates/product-test.yml`).
2. Fill frontmatter and body.
3. Render with `quarto render` from this repo root.
### Travel fields
Content for the PDF «اطلاعات کلی» block (only when using the travel template):
- `purpose` — هدف مأموریت
- `destinations` — مقصد (also used on the sidebar)
- `report-date` — تاریخ
### Product-test body
Put general info, samples, formula, and results in the body as Markdown tables. `destinations` is optional sidebar text. No `purpose` field is needed.
## Project layout
@@ -42,10 +64,12 @@ Outputs land in `_output/` (HTML + PDF). PDF is produced by `scripts/html-to-pdf
_quarto.yml
styles/report.css # HTML screen theme
styles/print.css # PDF / print (typst-templates match)
filters/print-chrome.lua # title block + sidebar injection
filters/print-chrome.lua # title block + sidebar + travel meta
scripts/html-to-pdf.py # WeasyPrint post-render
assets/fonts/
assets/logo.png
templates/travel.yml
templates/product-test.yml
examples/travel-report.qmd
examples/product-test.qmd
```

View File

@@ -1,4 +1,6 @@
---
metadata-files:
- ../templates/product-test.yml
title: "گزارش تست مواد اولیه"
subtitle: "دپارتمان جوهر"
company: "کیمیا رازی"

View File

@@ -0,0 +1 @@
/home/diaco/OpenCloud/Kimia Razi/Reports/Raw Material/Solvent & Dispersant/1405/04/گزارش تست نمونه‌های آزمایشگاهی سلونت MS/product-test.qmd

View File

@@ -1,4 +1,6 @@
---
metadata-files:
- ../templates/travel.yml
title: "گزارش مأموریت"
subtitle: "دپارتمان جوهر"
company: "کیمیا رازی"

View File

@@ -141,6 +141,7 @@ function Meta(meta)
local logo_path = resolve_logo_path(stringify(meta.logofile or "assets/logo.png"))
local logo_uri = file_to_data_uri(logo_path)
local destinations = escape_html(meta_list_join(meta.destinations, " - "))
local report_type = stringify(meta["report-type"])
local purpose = stringify(meta.purpose)
local report_date = escape_html(meta["report-date"] or meta.date or "")
local authors = escape_html(author_names(meta))
@@ -190,8 +191,9 @@ function Meta(meta)
</div>
]], running_logo, company, subtitle)
-- Travel meta is gated on report-type (from templates/travel.yml), not on purpose.
local travel = ""
if purpose ~= nil and purpose ~= "" then
if report_type == "travel" then
travel = string.format([[
<div class="print-travel-meta print-only">
<hr class="rule" />

View File

@@ -216,7 +216,7 @@ nav.toc-active,
width: auto;
}
/* Travel-report meta block (only when purpose is set) */
/* Travel-report meta block (injected when report-type is travel) */
.print-travel-meta {
margin: 12pt 0 24pt 0;
}

View File

@@ -0,0 +1,5 @@
# Product / raw-material test report template.
# Include from a .qmd with:
# metadata-files:
# - ../templates/product-test.yml
report-type: product-test

5
templates/travel.yml Normal file
View File

@@ -0,0 +1,5 @@
# Travel / mission report template.
# Include from a .qmd with:
# metadata-files:
# - ../templates/travel.yml
report-type: travel

View File

@@ -18,6 +18,9 @@ $endif$
$if(purpose)$
purpose: [$purpose$],
$endif$
$if(report-type)$
report-type: "$report-type$",
$endif$
$if(logofile)$
logo: "$logofile$",
$endif$

View File

@@ -51,6 +51,7 @@
company: none,
destinations: none,
purpose: none,
report-type: none,
logo: none,
doc,
) = {
@@ -110,8 +111,8 @@
)
]
// Travel reports pass `purpose`; product-test reports put general info in the body.
let show-travel-meta = purpose != none and purpose != ""
// Travel meta is gated on report-type (from templates/travel.yml), not on purpose.
let show-travel-meta = report-type == "travel"
if show-travel-meta {
v(12pt)