Build
This commit is contained in:
parent
a4c259072e
commit
4b21fcdd77
@ -54,6 +54,10 @@ MetaToml = TypedDict(
|
||||
)
|
||||
|
||||
|
||||
def sanitize_file_name(file: str) -> str:
|
||||
return file.replace("?", "")
|
||||
|
||||
|
||||
def read_meta_toml(file: Path) -> MetaToml:
|
||||
with file.open("rb") as f:
|
||||
base = tomllib.load(f)
|
||||
@ -132,6 +136,7 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
out = OUT_DIR / out_subdir
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
file_name = sanitize_file_name(f"{meta['title']}.pdf")
|
||||
res = subprocess.run(
|
||||
[
|
||||
TYPST_PATH,
|
||||
@ -140,7 +145,7 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
"main.typ",
|
||||
"--input",
|
||||
"show_solutions=false",
|
||||
f"{out}/{meta['title']}.pdf",
|
||||
f"{out}/{file_name}",
|
||||
],
|
||||
cwd=source_dir,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -153,13 +158,14 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
# Build solutions
|
||||
if meta["publish_solutions"]:
|
||||
log(f"Building typst (solutions): {source_dir}")
|
||||
file_name = sanitize_file_name(f"{meta['title']}.sols.pdf")
|
||||
res = subprocess.run(
|
||||
[
|
||||
TYPST_PATH,
|
||||
"compile",
|
||||
"--ignore-system-fonts",
|
||||
"main.typ",
|
||||
f"{out}/{meta['title']}.sols.pdf",
|
||||
f"{out}/{file_name}",
|
||||
],
|
||||
cwd=source_dir,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -213,8 +219,9 @@ def build_xetex(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
file_name = sanitize_file_name(f"{meta['title']}.pdf")
|
||||
try:
|
||||
shutil.copy(source_dir / "main.pdf", f"{out}/{meta['title']}.pdf")
|
||||
shutil.copy(source_dir / "main.pdf", f"{out}/{file_name}")
|
||||
except Exception as e:
|
||||
log(f"Error: {e}")
|
||||
log_error(res)
|
||||
@ -236,8 +243,9 @@ def build_xetex(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
file_name = sanitize_file_name(f"{meta['title']}.sols.pdf")
|
||||
try:
|
||||
shutil.copy(source_dir / "main.pdf", f"{out}/{meta['title']}.sols.pdf")
|
||||
shutil.copy(source_dir / "main.pdf", f"{out}/{file_name}")
|
||||
except Exception as e:
|
||||
log(f"Error: {e}")
|
||||
log_error(res)
|
||||
|
Loading…
x
Reference in New Issue
Block a user