added README
This commit is contained in:
46
.gallery/gallery.py
Normal file
46
.gallery/gallery.py
Normal file
@@ -0,0 +1,46 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user