Skip to content

Commit f6053cb

Browse files
committed
make default font sources behave differently for html (bunny) and typst (google)
1 parent 942ca6a commit f6053cb

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/command/render/pandoc.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ import {
202202
} from "../../core/markdown-pipeline.ts";
203203
import { getEnv } from "../../../package/src/util/utils.ts";
204204
import { canonicalizeTitlePostprocessor } from "../../format/html/format-html-title.ts";
205+
import {
206+
BrandFontBunny,
207+
BrandFontFile,
208+
BrandFontGoogle,
209+
} from "../../resources/types/schema-types.ts";
205210

206211
// in case we are running multiple pandoc processes
207212
// we need to make sure we capture all of the trace files
@@ -1359,18 +1364,25 @@ async function resolveExtras(
13591364
const ttf_urls = [], woff_urls: Array<string> = [];
13601365
if (brand?.data.typography) {
13611366
const fonts = brand.data.typography.fonts || [];
1362-
for (const font of fonts) {
1363-
if (font.source === "file") {
1367+
for (const _font of fonts) {
1368+
// if font lacks a source, we assume google in typst output
1369+
1370+
// deno-lint-ignore no-explicit-any
1371+
const source: string = (_font as any).source ?? "google";
1372+
if (source === "file") {
1373+
const font = _font as BrandFontFile;
13641374
for (const file of font.files || []) {
13651375
const path = typeof file === "object" ? file.path : file;
13661376
fontdirs.add(dirname(join(brand.brandDir, path)));
13671377
}
1368-
} else if (font.source === "bunny") {
1378+
} else if (source === "bunny") {
1379+
const font = _font as BrandFontBunny;
13691380
console.log(
13701381
"Font bunny is not yet supported for Typst, skipping",
13711382
font.family,
13721383
);
1373-
} else if (font.source === "google" /* || font.source === "bunny" */) {
1384+
} else if (source === "google" /* || font.source === "bunny" */) {
1385+
const font = _font as BrandFontGoogle;
13741386
let { family, style, weight } = font;
13751387
const parts = [family!];
13761388
if (style) {
@@ -1382,7 +1394,7 @@ async function resolveExtras(
13821394
parts.push(weight.join(","));
13831395
}
13841396
const response = await fetch(
1385-
`${base_urls[font.source]}?family=${parts.join(":")}`,
1397+
`${base_urls[source]}?family=${parts.join(":")}`,
13861398
);
13871399
const lines = (await response.text()).split("\n");
13881400
for (const line of lines) {

src/core/sass/brand.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,13 @@ const brandTypographyBundle = (
378378
for (const _resolvedFont of font) {
379379
const resolvedFont =
380380
_resolvedFont as (BrandFont | BrandFontGoogle | BrandFontBunny);
381-
if ((resolvedFont as any).source && resolvedFont.source !== "bunny") {
381+
// Typescript's type checker doesn't understand that it's ok to attempt
382+
// to access a property that might not exist on a type when you're
383+
// only testing for its existence.
384+
385+
// deno-lint-ignore no-explicit-any
386+
const source = (resolvedFont as any).source;
387+
if (source && source !== "bunny") {
382388
return undefined;
383389
}
384390
const thisFamily = resolvedFont.family;

0 commit comments

Comments
 (0)