Support specifying content path in arguments

This commit is contained in:
Artemis Tosini 2023-12-01 02:40:44 +00:00
parent 358e68c8db
commit 72fbcb42d6
Signed by: artemist
GPG key ID: EE5227935FE3FF18
2 changed files with 19 additions and 2 deletions

View file

@ -116,7 +116,7 @@
let content_fn = if args.no_content { let content_fn = if args.no_content {
_ => [] _ => []
} else { } else {
import "content/content.typ" import "cache/content/content.typ"
content.content content.content
} }

View file

@ -5,6 +5,7 @@ import csv
import hashlib import hashlib
import json import json
import os import os
import pathlib
import string import string
import typing import typing
import urllib.parse import urllib.parse
@ -160,6 +161,14 @@ parser.add_argument(
help="CSV file containing addresses", help="CSV file containing addresses",
) )
parser.add_argument(
"-i",
"--content-path",
default="content",
type=str,
help="Directory containing content files",
)
parser.add_argument( parser.add_argument(
"-n", "-n",
"--no-content", "--no-content",
@ -216,6 +225,14 @@ for row in rows:
} }
] ]
# Typst can't access files outside the project root, except through a symlink
# Create one in cache to use here
if not os.path.exists("cache"):
os.mkdir("cache")
p = pathlib.Path("cache/content")
p.unlink(missing_ok=True)
p.symlink_to(args.content_path)
cards = cards * args.count cards = cards * args.count
serial = imb.get_first_serial() serial = imb.get_first_serial()
@ -246,7 +263,7 @@ os.execlp(
"typst", "typst",
"watch" if args.watch else "compile", "watch" if args.watch else "compile",
"--font-path", "--font-path",
"content", args.content_path,
"--font-path", "--font-path",
os.getenv("TYPST_FONT_PATHS"), os.getenv("TYPST_FONT_PATHS"),
args.template, args.template,