Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/resources/filters/modules/brand/brand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ local function get_logo(name)
local brand = param("brand")
brand = brand and brand.processedData -- from src/core/brand/brand.ts
if not brand then return nil end
-- todo convert logo options from CSS to Typst
return brand.logo and brand.logo[name]
end

Expand Down
38 changes: 18 additions & 20 deletions src/resources/filters/quarto-post/typst-brand-yaml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,44 +216,42 @@ function render_typst_brand_yaml()
-- logo
local logo = param('logo')
local logoOptions = {}
local foundSrc = null
local foundLogo = null
if logo then
if type(logo) == 'string' then
foundSrc = _quarto.modules.brand.get_logo(logo) or logo
foundLogo = _quarto.modules.brand.get_logo(logo) or {light={path=logo}}
elseif type(logo) == 'table' then
for k, v in pairs(logo) do
logoOptions[k] = v
end
if logo.src then
foundSrc = _quarto.modules.brand.get_logo(logo.src) or logo.src
if logo.path then
foundLogo = _quarto.modules.brand.get_logo(logo.path) or {light={path=logo}}
end
end
end
if not foundSrc and brand.processedData.logo then
if not foundLogo and brand.processedData.logo then
local tries = {'large', 'small', 'medium'} -- low to high priority
for _, try in ipairs(tries) do
local src = _quarto.modules.brand.get_logo(try)
if src then
foundSrc = src
end
end
foundLogo = _quarto.modules.brand.get_logo('medium')
or _quarto.modules.brand.get_logo('small')
or _quarto.modules.brand.get_logo('large')
end
if foundSrc then
if type(foundSrc) == "string" then
logoOptions.src = foundSrc
elseif foundSrc.light then
logoOptions.src = foundSrc.light
elseif foundSrc.dark then
logoOptions.src = foundSrc.dark
if foundLogo then
if foundLogo.light then
logoOptions.path = foundLogo.light.path
logoOptions.alt = foundLogo.light.alt
elseif foundLogo.dark then
logoOptions.path = foundLogo.dark.path
logoOptions.alt = foundLogo.dark.alt
end
-- todo: resolve logoOptions.src path
-- todo: path relative to brand.yaml
logoOptions.padding = _quarto.modules.typst.css.translate_length(logoOptions.padding or '0.5in')
logoOptions.width = _quarto.modules.typst.css.translate_length(logoOptions.width or '2in')
logoOptions.location = logoOptions.location and
location_to_typst_align(logoOptions.location) or 'left+top'
quarto.log.debug('logo options', logoOptions)
local altProp = logoOptions.alt and (', alt: "' .. logoOptions.alt .. '"') or ''
quarto.doc.include_text('in-header',
'#set page(background: align(' .. logoOptions.location .. ', box(inset: ' .. logoOptions.padding .. ', image("' .. logoOptions.src .. '", width: ' .. logoOptions.width .. '))))')
'#set page(background: align(' .. logoOptions.location .. ', box(inset: ' .. logoOptions.padding .. ', image("' .. logoOptions.path .. '", width: ' .. logoOptions.width .. altProp .. '))))')
end
end
end,
Expand Down
10 changes: 4 additions & 6 deletions tests/docs/smoke-all/typst/brand-yaml/logo/posit/_brand.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
logo:
images:
posit-logo-light-medium:
path: posit-logo-2024.svg
alt: Posit Logo
brand-typst-with-good-padding: good-padding.png

small: posit-icon.png
medium:
light: posit-logo-2024.svg
dark: posit-reverse.png
large: posit-logo-2024.svg
medium: posit-logo-light-medium
defaults:
quarto:
format:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _quarto:
typst:
ensureTypstFileRegexMatches:
-
- '#set page\(background: align\(left\+top, box\(inset: 0.5in, image\("posit-logo-2024.svg", width: 2in\)\)\)\)'
- '#set page\(background: align\(left\+top, box\(inset: 0.5in, image\("posit-logo-2024.svg", width: 2in, alt: "Posit Logo"\)\)\)\)'
- []
---

Expand Down
4 changes: 3 additions & 1 deletion tests/docs/smoke-all/typst/brand-yaml/logo/quarto/_brand.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
logo:
large: quarto.png
images:
large-light: quarto.png
large: large-light
defaults:
quarto:
format:
Expand Down
Loading