summaryrefslogtreecommitdiff
path: root/build.py
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2022-10-23 13:54:00 +0300
committerYuval Adam <_@yuv.al>2022-10-23 13:54:00 +0300
commit9d14b0297eb7e0d8e40ba482acb632dc1a61517a (patch)
treedae2ca435ea477f28763353f607ab368ab6fac8f /build.py
parentc0286a378d5a33dd0d8f475f304421e081a3904f (diff)
Add basic build structure and files
Diffstat (limited to 'build.py')
-rw-r--r--build.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/build.py b/build.py
new file mode 100644
index 0000000..f6cba01
--- /dev/null
+++ b/build.py
@@ -0,0 +1,43 @@
+import yaml
+
+from jinja2 import Environment, PackageLoader, select_autoescape
+from os import listdir, mkdir
+from pathlib import Path
+from shutil import copyfile
+
+ROOT_PATH = Path(__file__).parent
+
+NAMES_DIR = ROOT_PATH / "names"
+BUILD_DIR = ROOT_PATH / "build"
+STATIC_DIR = ROOT_PATH / "static"
+
+REQUIRED_FIELDS = set(["domain", "name", "email"])
+
+TEMPLATES = ["index.html"]
+
+# copy static files
+if not BUILD_DIR.exists():
+ mkdir(BUILD_DIR)
+for f in listdir(STATIC_DIR):
+ copyfile(STATIC_DIR / f, BUILD_DIR / f)
+
+# process all name yamls
+names = []
+for name in listdir(NAMES_DIR):
+ with open(NAMES_DIR / name, "r") as f:
+ fields = yaml.load(f.read(), Loader=yaml.Loader)
+ missing_fields = REQUIRED_FIELDS - set(fields.keys())
+ if missing_fields:
+ raise Exception(f"Missing required fields {missing_fields} in {name}")
+ names.append(fields)
+
+# render templates
+env = Environment(
+ loader=PackageLoader("build"),
+ autoescape=select_autoescape()
+)
+for template in TEMPLATES:
+ t = env.get_template(template)
+ index = t.render(names=names)
+ with open(BUILD_DIR / "index.html", "w") as f:
+ f.write(index) \ No newline at end of file