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