Skip to content

Commit 9cfe15f

Browse files
typst: declare brand-logo and brand-logo-images dictionaries
brand processedData resolves paths in logo.images
1 parent 9a0a073 commit 9cfe15f

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

news/changelog-1.8.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ All changes included in 1.8:
4848
- ([#12695](https://github.com/quarto-dev/quarto-cli/issues/12695)): Resolve Typst `font-paths` that start with `/` relative to project root.
4949
- ([#12739](https://github.com/quarto-dev/quarto-cli/pull/12739)): Remove unused variable `heading-background-color` and `heading-decoration` from Typst's templates. They are leftover from previous change, and not part of Brand.yml schema for typography of headings.
5050
- ([#12815](https://github.com/quarto-dev/quarto-cli/issues/12815)): Do not crash when floats have no content.
51+
- ([#13119](https://github.com/quarto-dev/quarto-cli/pull/13119)): Expose `brand.logo` metadata as Typst dictionaries.
5152

5253
### `beamer`
5354

src/core/brand/brand.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
BrandColorLightDark,
1111
BrandFont,
1212
BrandLogoExplicitResource,
13+
BrandLogoResource,
1314
BrandLogoSingle,
1415
BrandLogoUnified,
1516
BrandNamedLogo,
@@ -143,11 +144,7 @@ export class Brand {
143144
}
144145
}
145146
for (const [key, value] of Object.entries(data.logo?.images ?? {})) {
146-
if (typeof value === "string") {
147-
logo.images[key] = { path: value };
148-
} else {
149-
logo.images[key] = value;
150-
}
147+
logo.images[key] = this.resolvePath(value);
151148
}
152149

153150
return {
@@ -240,11 +237,7 @@ export class Brand {
240237
return fonts ?? [];
241238
}
242239

243-
getLogoResource(name: string): BrandLogoExplicitResource {
244-
const entry = this.data.logo?.images?.[name];
245-
if (!entry) {
246-
return { path: name };
247-
}
240+
resolvePath(entry: BrandLogoResource) {
248241
const pathPrefix = relative(this.projectDir, this.brandDir);
249242
if (typeof entry === "string") {
250243
return { path: join(pathPrefix, entry) };
@@ -255,6 +248,13 @@ export class Brand {
255248
};
256249
}
257250

251+
getLogoResource(name: string): BrandLogoExplicitResource {
252+
const entry = this.data.logo?.images?.[name];
253+
if (!entry) {
254+
return { path: name };
255+
}
256+
return this.resolvePath(entry);
257+
}
258258
getLogo(name: BrandNamedLogo): BrandLogoExplicitResource | undefined {
259259
const entry = this.data.logo?.[name];
260260
if (!entry) {

src/resources/filters/quarto-post/typst-brand-yaml.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,33 @@ function render_typst_brand_yaml()
9696
local decl = '#let brand-color-background = ' .. to_typst_dict_indent(themebk)
9797
quarto.doc.include_text('in-header', decl)
9898
end
99+
if brand.processedData.logo and next(brand.processedData.logo) then
100+
local logo = brand.processedData.logo
101+
if logo.images then
102+
local declImage = {}
103+
for name, image in pairs(logo.images) do
104+
declImage[name] = {
105+
path = quote_string(image.path):gsub('\\', '\\\\'),
106+
alt = quote_string(image.alt),
107+
}
108+
end
109+
if next(declImage) then
110+
quarto.doc.include_text('in-header', '#let brand-logo-images = ' .. to_typst_dict_indent(declImage))
111+
end
112+
end
113+
local declLogo = {}
114+
for _, size in pairs({'small', 'medium', 'large'}) do
115+
if logo[size] then
116+
declLogo[size] = {
117+
path = quote_string(logo[size].path):gsub('\\', '\\\\'),
118+
alt = quote_string(logo[size].alt),
119+
}
120+
end
121+
end
122+
if next(declLogo) then
123+
quarto.doc.include_text('in-header', '#let brand-logo = ' .. to_typst_dict_indent(declLogo))
124+
end
125+
end
99126
local function conditional_entry(key, value, quote_strings)
100127
if quote_strings == null then quote_strings = true end
101128
if not value then return '' end

tests/docs/smoke-all/typst/brand-yaml/logo/posit/brand-logo.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ _quarto:
99
typst:
1010
ensureTypstFileRegexMatches:
1111
-
12+
- '#let brand-logo-images = \(\s*brand-typst-with-good-padding: \(\s*path: "good-padding\.png"\s*\),\s*posit-logo-light-medium: \(\s*alt: "Posit Logo",\s*path: "posit-logo-2024.svg"\s*\)'
13+
- '#let brand-logo = \(\s*medium: \(\s*alt: "Posit Logo",\s*path: "posit-logo-2024\.svg"\s*\)\s*\)'
1214
- '#set page\(background: align\(left\+top, box\(inset: 0.75in, image\("posit-logo-2024.svg", width: 1.5in, alt: "Posit Logo"\)\)\)\)'
1315
- []
1416
---

tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand-logo.qmd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ _quarto:
1111
typst:
1212
ensureTypstFileRegexMatches:
1313
-
14+
- '#let brand-logo-images = \(\s*large-light: \(\s*path: "brand_yaml(/|\\\\)resources(/|\\\\)quarto.png"\s*\)\s*\)'
15+
- '#let brand-logo = \(\s*large: \(\s*path: "brand_yaml(/|\\\\)resources(/|\\\\)quarto.png"\s*\)\s*\)'
1416
- '#set page\(background: align\(center\+top, box\(inset: 2em, image\("brand_yaml(/|\\\\)resources(/|\\\\)quarto.png", width: 225pt\)\)\)\)'
17+
- '#image\(brand-logo-images\.large-light\.path, alt:"from brand-logo-images"\)'
1518
- []
1619
---
1720

1821
{{< lipsum 4 >}}
1922

23+
```{=typst}
24+
#image(brand-logo-images.large-light.path, alt:"from brand-logo-images")
25+
```

0 commit comments

Comments
 (0)