Skip to content

Commit

Permalink
feat: add support for brand.yml (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanouil authored Dec 8, 2024
1 parent 5521c35 commit 62ad587
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ or in your document yaml
```yaml
format:
invoice-typst:
lang: en_UK
lang: en
region: UK
papersize: a4
margin:
x: 2.5cm
Expand All @@ -45,4 +46,20 @@ format:
fontsize: 12pt
```
Using [`_brand.yml`](https://posit-dev.github.io/brand-yml/) ([v1.2.0](../../releases/tag/1.2.0)):

```markdown
brand:
typography:
fonts:
- family: Alegreya Sans
source: google
base:
family: "Alegreya Sans"
size: 12pt
headings:
family: "Alegreya Sans"
color: dodgerblue
```

You can view a preview of the rendered template below: [Invoice Template](https://m.canouil.dev/quarto-invoice/index.pdf)
4 changes: 2 additions & 2 deletions _extensions/invoice/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: Invoice (Typst)
author: Mickaël Canouil
version: 1.1.1
quarto-required: ">=1.4.0"
version: 1.2.0
quarto-required: ">=1.6.39"
contributes:
formats:
typst:
Expand Down
26 changes: 26 additions & 0 deletions _extensions/invoice/typst-show.typ
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ $if(title)$
$endif$
$if(logo)$
logo: "$logo$",
$elseif(brand.logo)$
font: ("$brand.logo$",),
$endif$
$if(sender)$
sender: (
Expand Down Expand Up @@ -55,6 +57,9 @@ $endif$
$if(lang)$
lang: "$lang$",
$endif$
$if(region)$
region: "$region$",
$endif$
$if(margin)$
margin: ($for(margin/pairs)$$margin.key$: $margin.value$,$endfor$),
$endif$
Expand All @@ -63,8 +68,29 @@ $if(papersize)$
$endif$
$if(mainfont)$
font: ("$mainfont$",),
$elseif(brand.typography.base.family)$
font: ("$brand.typography.base.family$",),
$endif$
$if(fontsize)$
fontsize: $fontsize$,
$elseif(brand.typography.base.size)$
fontsize: $brand.typography.base.size$,
$endif$
$if(title)$
$if(brand.typography.headings.family)$
heading-family: ("$brand.typography.headings.family$",),
$endif$
$if(brand.typography.headings.weight)$
heading-weight: $brand.typography.headings.weight$,
$endif$
$if(brand.typography.headings.style)$
heading-style: "$brand.typography.headings.style$",
$endif$
$if(brand.typography.headings.color)$
heading-color: $brand.typography.headings.color$,
$endif$
$if(brand.typography.headings.line-height)$
heading-line-height: $brand.typography.headings.line-height$,
$endif$
$endif$
)
19 changes: 17 additions & 2 deletions _extensions/invoice/typst-template.typ
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,25 @@
penalty: "40",
paper: "a4",
margin: (x: 2.5cm, y: 2.5cm),
lang: "en_UK",
font: ("Alegreya Sans", "Alegreya Sans SC", "Alegreya Sans", "Alegreya Sans SC"),
lang: "en",
region: "UK",
font: "Alegreya Sans",
heading-family: none,
heading-weight: "bold",
heading-style: "normal",
heading-color: black,
heading-line-height: 0.65em,
fontsize: 12pt,
title-size: 1.5em,
body
) = {
show heading: it => [
#set par(leading: heading-line-height)
#set text(font: heading-family, weight: heading-weight, style: heading-style, fill: heading-color)
#it.body
]
let issued = parse-date(invoice.at("issued"))
if "penalty" in invoice and invoice != none {
let penalty = invoice.at("penalty", default: "40")
Expand All @@ -66,6 +80,7 @@
set par(justify: true)
set text(
lang: lang,
region: region,
font: font,
size: fontsize,
)
Expand Down
13 changes: 11 additions & 2 deletions template.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ format:
margin:
x: 2.5cm
y: 2.5cm
mainfont: "Alegreya Sans"
fontsize: 12pt
brand:
typography:
fonts:
- family: Alegreya Sans
source: google
base:
family: "Alegreya Sans"
size: 12pt
headings:
color: dodgerblue
---

<!--
Currently hard to get the right style for the table in markdown.
+-----------------------------------+-----+------------+-------+-----------------+
| Details | Qty | Unit price | VAT % | Total excl. VAT |
+===================================+=====+============+=======+=================+
Expand Down

0 comments on commit 62ad587

Please sign in to comment.