diff --git a/README.md b/README.md index 0a33568..7496bb9 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ jobs: - name: Typst uses: lvignoli/typst-action@main with: + options: | + --font-path + fonts source_file: | first_file.typ second_file.typ @@ -78,3 +81,17 @@ Repository [lvignoli/typst-action-example](https://github.com/lvignoli/typst-act - I was hasty to tag for a v1. I have now deleted it. As long as Typst is not in a stable state, the action will stay in v0. You should use `lvignoli/typst-action@main` in the meantime. + +## Extra + +To specify the output filename use `:` in the filename to denote the name, such as: +``` + - name: Typst + uses: lvignoli/typst-action@main + with: + source_file: | + first_file.typ:first.pdf + second_file.typ + third_and_final_file.typ:third.pdf + +``` \ No newline at end of file diff --git a/entrypoint.py b/entrypoint.py index 3aab31a..1d042a4 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -4,12 +4,14 @@ import sys -def compile(filename: str, options: list[str]) -> bool: +def compile(filename: str, options: list[str], outputfilename: str | None) -> bool: """Compiles a Typst file with the specified global options. Returns True if the typst command exited with status 0, False otherwise. """ command = ["typst", "compile"] + options + [filename] + if outputfilename is not None: + command.append(outputfilename) logging.debug("Running: " + " ".join(command)) result = subprocess.run(command, capture_output=True, text=True) @@ -27,12 +29,15 @@ def main(): logging.basicConfig(level=logging.INFO) # Parse the positional arguments, expected in the following form - # 1. The Typst files to compile in a line separated string + # 1. The Typst files to compile in a line separated string. Optionally To + # specify the ooutput name separate it with a : so such as: + # input.typ:output.pdf # 2. The global Typst CLI options, in a line separated string. It means each # whitespace separated field should be on its own line. source_files = sys.argv[1].splitlines() options = sys.argv[2].splitlines() + version = subprocess.run( ["typst", "--version"], capture_output=True, text=True ).stdout @@ -40,12 +45,17 @@ def main(): success: dict[str, bool] = {} - for filename in source_files: + for filename_pair in source_files: + (filename, _, outputfilename) = filename_pair.partition(":") filename = filename.strip() if filename == "": continue + if outputfilename == "": + outputfilename = None + elif outputfilename is not None: + outputfilename = outputfilename.strip() logging.info(f"Compiling {filename}…") - success[filename] = compile(filename, options) + success[filename] = compile(filename, options, outputfilename) # Log status of each input files. for filename, status in success.items():