Skip to content

Commit

Permalink
📄 Prioritize project-level parts for project-level typst export (#1743)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkoch authored Jan 9, 2025
1 parent 479db78 commit 1127a5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-months-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-cli': patch
---

Prioritize project-level parts for project-level typst export
28 changes: 26 additions & 2 deletions packages/myst-cli/src/build/typst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,31 @@ export async function localArticleToTypstTemplated(
macros: [],
commands: {},
};
const state = session.store.getState();
const projectFrontmatter = selectors.selectLocalProjectConfig(state, projectPath ?? '.') ?? {};
if (file === selectors.selectCurrentProjectFile(state)) {
// If export is defined at the project level, prioritize project parts over page parts
partDefinitions.forEach((def) => {
const part = extractTypstPart(
session,
{ type: 'root', children: [] },
{},
def,
projectFrontmatter,
templateYml,
);
if (Array.isArray(part)) {
// This is the case if def.as_list is true
part.forEach((item) => {
collected = mergeTypstTemplateImports(collected, item);
});
parts[def.id] = part.map(({ value }) => value);
} else if (part != null) {
collected = mergeTypstTemplateImports(collected, part);
parts[def.id] = part?.value ?? '';
}
});
}
const hasGlossaries = false;
const results = await Promise.all(
content.map(async ({ mdast, frontmatter, references }, ind) => {
Expand Down Expand Up @@ -311,8 +336,7 @@ export async function localArticleToTypstTemplated(
frontmatter = content[0].frontmatter;
typstContent = results[0].value;
} else {
const state = session.store.getState();
frontmatter = selectors.selectLocalProjectConfig(state, projectPath ?? '.') ?? {};
frontmatter = projectFrontmatter;
const { dir, name, ext } = path.parse(output);
typstContent = '';
let fileInd = 0;
Expand Down

0 comments on commit 1127a5a

Please sign in to comment.