From: Georgios Atheridis Date: Mon, 6 Feb 2023 03:02:02 +0000 (+0000) Subject: Add Option to Update Multiple Pages X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=8b2b10f3afc81824f28de82b75b824319c2a6e9e;p=personal%2Fsigma.git Add Option to Update Multiple Pages The --page flag has been changed to --pages and can now take a whole directory. It's possible to update the whole site with one command. --- diff --git a/sigma b/sigma index c92db15..e03b4ee 100755 --- a/sigma +++ b/sigma @@ -159,19 +159,30 @@ def main(args): initialize_values(data) - rel_path = os.path.relpath(args.page, data["_PAGE_ROOT"]) - rel_path_no_type, file_type = os.path.splitext(rel_path) - namespace = split_path(rel_path_no_type) - os.makedirs(os.path.join(data["_OUT"], os.path.split(rel_path)[0]), exist_ok=True) - if file_type == ".md": - rel_path = rel_path_no_type + ".html" - with open(os.path.join(data["_OUT"], rel_path), "w") as out_file: - out_file.write(generate_output(args.page, data, namespace)) + if not args.pages: + pages = [] + for dir in os.walk(data["_PAGE_ROOT"]): + for file in dir[2]: + pages.append(os.path.join(dir[0], file)) + else: + pages = args.pages + + for page in pages: + rel_path = os.path.relpath(page, data["_PAGE_ROOT"]) + rel_path_no_type, file_type = os.path.splitext(rel_path) + namespace = split_path(rel_path_no_type) + os.makedirs( + os.path.join(data["_OUT"], os.path.split(rel_path)[0]), exist_ok=True + ) + if file_type == ".md": + rel_path = rel_path_no_type + ".html" + with open(os.path.join(data["_OUT"], rel_path), "w") as out_file: + out_file.write(generate_output(page, data, namespace)) if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--page", type=str) + parser.add_argument("--pages", type=str, nargs="*") parser.add_argument("--page-root", type=str) parser.add_argument("--templates", type=str) parser.add_argument("--data", default="data.toml", type=argparse.FileType("rb"))