import subprocess import sys import glob slug = sys.argv[1] def run_command(command, verbose=1): try: result = subprocess.run(command, check=True, capture_output=True, text=True) except subprocess.CalledProcessError as e: print(f"Error building book: {e.stderr}") sys.exit(1) if verbose > 0: print(f"Output: {result.stdout}") return result notebooks = glob.glob("*.ipynb") if len(notebooks) > 1: print("More than one .ipynb notebook found --> assuming this is a book") # build book command = [ "jb", "build", "--config", "_config.yml", "--toc", "_toc.yml", ".", ] run_command(command) # copy build outputs to 'html' dir command = ["cp", "-r", "_build/html", "html"] run_command(command) else: # build single notebook command = [ "jb", "build", "--config", "_config.yml", f"{slug}.ipynb", ] run_command(command) # copy build outputs to 'html' dir command = ["cp", "-r", f"_build/_page/{slug}/html", "html"] run_command(command)