Skip to content

Commit d60ef28

Browse files
typst brand yaml working under new schema
reverts changes that allowed logging font paths from lua to the output recipe, because it's much simpler to do this in typescript
1 parent 899602c commit d60ef28

File tree

13 files changed

+67
-95
lines changed

13 files changed

+67
-95
lines changed

src/command/render/output-typst.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ export function typstPdfOutputRecipe(
6565
const pdfOutput = join(inputDir, inputStem + ".pdf");
6666
const typstOptions: TypstCompileOptions = {
6767
quiet: options.flags?.quiet,
68-
// use recipe that may have been modified, not format which has not
69-
fontPaths: asArray(recipe.format.metadata?.[kFontPaths]) as string[],
68+
fontPaths: asArray(format.metadata?.[kFontPaths]) as string[],
7069
};
7170
if (project?.dir) {
7271
typstOptions.rootDir = project.dir;

src/command/render/pandoc-dependencies-html.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,6 @@ export function readAndInjectDependencies(
138138
});
139139
}
140140

141-
// this should be resolveMetadata returning an object
142-
// like {'output-recipe': metadata}
143-
export function resolveTypstFontPaths(
144-
dependenciesFile: string,
145-
) {
146-
const dependencyJsonStream = Deno.readTextFileSync(dependenciesFile);
147-
const fontPaths: string[] = [];
148-
lines(dependencyJsonStream).forEach((json) => {
149-
if (json) {
150-
const dependency = JSON.parse(json);
151-
if (dependency.type === "typst-font-path") {
152-
const path = dependency?.content?.path;
153-
fontPaths.push(path);
154-
}
155-
}
156-
});
157-
return fontPaths;
158-
}
159-
160141
export function resolveDependencies(
161142
extras: FormatExtras,
162143
inputDir: string,

src/command/render/pandoc.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ import { kDefaultHighlightStyle } from "./constants.ts";
139139
import {
140140
HtmlPostProcessor,
141141
HtmlPostProcessResult,
142-
OutputRecipe,
143142
PandocOptions,
144143
RunPandocResult,
145144
} from "./types.ts";
@@ -176,7 +175,6 @@ import { resolveAndFormatDate, resolveDate } from "../../core/date.ts";
176175
import { katexPostProcessor } from "../../format/html/format-html-math.ts";
177176
import {
178177
readAndInjectDependencies,
179-
resolveTypstFontPaths,
180178
writeDependencies,
181179
} from "./pandoc-dependencies-html.ts";
182180
import {
@@ -420,13 +418,13 @@ export async function runPandoc(
420418
);
421419

422420
const extras = await resolveExtras(
421+
options.source,
423422
inputExtras,
424423
options.format,
425424
cwd,
426425
options.libDir,
427426
options.services.temp,
428427
dependenciesFile,
429-
options.recipe,
430428
options.project,
431429
);
432430

@@ -1283,13 +1281,13 @@ function cleanupPandocMetadata(metadata: Metadata) {
12831281
}
12841282

12851283
async function resolveExtras(
1284+
input: string,
12861285
extras: FormatExtras, // input format extras (project, format, brand)
12871286
format: Format,
12881287
inputDir: string,
12891288
libDir: string,
12901289
temp: TempContext,
12911290
dependenciesFile: string,
1292-
recipe: OutputRecipe,
12931291
project: ProjectContext,
12941292
) {
12951293
// resolve format resources
@@ -1346,15 +1344,25 @@ async function resolveExtras(
13461344

13471345
// perform typst-specific merging
13481346
if (isTypstOutput(format.pandoc)) {
1349-
extras.postprocessors = extras.postprocessors || [];
1350-
extras.postprocessors.push(async () => {
1351-
// gw: IMO this could be way more general as resolveMetadata
1352-
// returning all metadata found in the file
1353-
// then apply output-recipe and any others found using mergeConfigs
1354-
// would not be format-specific
1355-
const fontPaths = await resolveTypstFontPaths(dependenciesFile);
1356-
recipe.format.metadata[kFontPaths] = fontPaths;
1357-
});
1347+
const brand = await project.resolveBrand(input);
1348+
const fontdirs: Set<string> = new Set();
1349+
if (brand?.data.typography) {
1350+
const fonts = brand.data.typography.fonts || [];
1351+
for (const font of fonts) {
1352+
if (font.source === "file") {
1353+
for (const file of font.files || []) {
1354+
const path = typeof file === "object" ? file.path : file;
1355+
fontdirs.add(dirname(join(brand.brandDir, path)));
1356+
}
1357+
}
1358+
}
1359+
}
1360+
let fontPaths = format.metadata[kFontPaths] as Array<string> || [];
1361+
if (typeof fontPaths === "string") {
1362+
fontPaths = [fontPaths];
1363+
}
1364+
fontPaths.push(...fontdirs);
1365+
format.metadata[kFontPaths] = fontPaths;
13581366
}
13591367

13601368
// Process format resources

src/command/render/render.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ export async function renderPandoc(
191191
metadata: executeResult.metadata,
192192
quiet,
193193
flags: context.options.flags,
194-
recipe,
195194
};
196195

197196
// add offset if we are in a project

src/command/render/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@ export interface PandocOptions {
226226

227227
// optional offset from file to project dir
228228
offset?: string;
229-
230-
// output recipe (this makes many of above options redundant)
231-
recipe: OutputRecipe;
232229
}
233230

234231
// command line flags that we need to inspect

src/core/brand/brand.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ export class Brand {
177177
return undefined;
178178
}
179179
const typography = this.data.typography;
180-
if (name === "base") {
181-
return typography.base;
180+
switch (name) {
181+
case "base":
182+
return typography.base;
183+
case "headings":
184+
return typography.headings;
185+
case "link":
186+
return typography.link;
187+
case "monospace":
188+
return typography.monospace;
182189
}
183-
if (name === "headings") {
184-
return typography.headings;
185-
}
186-
if (name === "link") {
187-
return typography.link;
188-
}
189-
190190
return undefined;
191191
}
192192

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,6 @@ function render_typst_brand_yaml()
147147
if headings and headings.family then
148148
meta['title-font'] = headings.family
149149
end
150-
-- really should be _brand.yml directory
151-
local projectDir = pandoc.path.directory(quarto.doc.input_file)
152-
local fontdirs = {}
153-
for _, fontName in ipairs({'base', 'headings', 'monospace'}) do
154-
local font = _quarto.modules.brand.get_typography(fontName)
155-
if font and font.files then
156-
local files = font.files
157-
if type(files) == 'string' then files = {files} end
158-
for _, file in ipairs(files) do
159-
local dir = pandoc.path.directory(pandoc.path.normalize(pandoc.path.join({projectDir, file})))
160-
fontdirs[dir] = true
161-
end
162-
end
163-
end
164-
for fontdir, _ in pairs(fontdirs) do
165-
quarto.doc.add_typst_font_path(fontdir)
166-
end
167150
return meta
168151
end
169152
}

tests/docs/smoke-all/typst/brand-yaml/color/exper/_brand.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
color:
2-
with:
2+
palette:
33
blue: "#447099"
44
orange: "#EE6331"
55
gray: "#404041"

tests/docs/smoke-all/typst/brand-yaml/color/homedepot/_brand.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
color:
2-
with:
2+
palette:
33
orange: "#F96302"
44
white: "#FFFFFF"
55
black: "#000000"

tests/docs/smoke-all/typst/brand-yaml/color/posit/_brand.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
color:
2-
with:
2+
palette:
33
blue: "#447099"
44
orange: "#EE6331"
55
gray: "#404041"

0 commit comments

Comments
 (0)