47 lines
1.0 KiB
Python
47 lines
1.0 KiB
Python
import json
|
|
import os
|
|
import subprocess
|
|
|
|
|
|
def compile(root_path):
|
|
subprocess.run([
|
|
"typst",
|
|
"c",
|
|
"--root="+root_path,
|
|
os.path.join(root_path, ".gallery", "gallery.typ"),
|
|
os.path.join(root_path, ".gallery", "page-{n}.png")
|
|
])
|
|
|
|
|
|
def query(root_path):
|
|
proc = subprocess.run([
|
|
"typst",
|
|
"query",
|
|
"--root="+root_path,
|
|
os.path.join(root_path, ".gallery", "gallery.typ"),
|
|
"metadata"
|
|
], capture_output=True)
|
|
return json.loads(proc.stdout)
|
|
|
|
|
|
def main():
|
|
root_path = os.path.abspath(
|
|
os.path.join(
|
|
os.path.dirname(__file__),
|
|
os.path.pardir
|
|
)
|
|
)
|
|
|
|
compile(root_path)
|
|
metadata = query(root_path)
|
|
for entry in metadata:
|
|
name = entry["value"]["name"]
|
|
page = entry["value"]["page"]
|
|
from_path = os.path.join(root_path, ".gallery", f"page-{page}.png")
|
|
to_path = os.path.join(root_path, ".gallery", f"{name}.png")
|
|
os.rename(from_path, to_path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|