Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📄 Prioritize project-level parts for project-level typst export #1743

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -66,8 +66,8 @@
mdast: GenericParent,
references: References,
frontmatter: PageFrontmatter,
templateYml: TemplateYml | null,

Check warning on line 69 in packages/myst-cli/src/build/typst.ts

View workflow job for this annotation

GitHub Actions / lint

'templateYml' is defined but never used
printGlossaries: boolean,

Check warning on line 70 in packages/myst-cli/src/build/typst.ts

View workflow job for this annotation

GitHub Actions / lint

'printGlossaries' is defined but never used
) {
const pipe = unified().use(mystToTypst, {
math: frontmatter?.math,
Expand Down Expand Up @@ -267,6 +267,31 @@
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 @@
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
Loading