Add Option to Update Multiple Pages
authorGeorgios Atheridis <georgios@atheridis.org>
Mon, 6 Feb 2023 03:02:02 +0000 (03:02 +0000)
committerGeorgios Atheridis <georgios@atheridis.org>
Mon, 6 Feb 2023 03:02:02 +0000 (03:02 +0000)
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.

sigma

diff --git a/sigma b/sigma
index c92db1502fc5742e99a6f9cff698b15775305611..e03b4ee8853871402d7b400a30862f2280ed26bf 100755 (executable)
--- 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"))