summaryrefslogtreecommitdiff
path: root/build.py3
diff options
context:
space:
mode:
Diffstat (limited to 'build.py3')
-rwxr-xr-xbuild.py363
1 files changed, 63 insertions, 0 deletions
diff --git a/build.py3 b/build.py3
new file mode 100755
index 0000000..03c4cb5
--- /dev/null
+++ b/build.py3
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import brotli
+import gzip
+import os
+import shutil
+
+
+def clean_target():
+ if os.path.exists('target'):
+ shutil.rmtree('target')
+ os.mkdir('target')
+
+
+def compile_all(path: str, target: str):
+ for file in os.listdir(path):
+ src = os.path.join(path, file)
+ base, ext = os.path.splitext(file)
+ if os.path.isdir(src):
+ os.mkdir(os.path.join(target, file))
+ compile_all(src, os.path.join(target, file))
+ elif ext == '.kuht':
+ os.system(f"kuht {src} src/base.kuht -o {target}/{base}.html")
+
+
+def move_css(path: str):
+ for file in os.listdir(path):
+ if os.path.splitext(file)[1] == '.css':
+ shutil.copy(file, os.path.join('target', file))
+
+
+def compress_files(path: str):
+ for file in os.listdir(path):
+ file = os.path.join(path, file)
+ if os.path.isdir(file):
+ compress_files(file)
+ return
+
+ base, ext = os.path.splitext(file)
+ with open(file, 'rb') as f_in:
+ data = f_in.read()
+ with gzip.open(f"{file}.gz", 'wb') as f_out:
+ f_out.write(data)
+ with open(f"{file}.br", 'wb') as f_out:
+ f_out.write(brotli.compress(data, mode=brotli.MODE_TEXT))
+
+
+def main():
+ original_path = os.getcwd()
+ script_path = os.path.dirname(os.path.realpath(__file__))
+ os.chdir(script_path)
+
+ clean_target()
+ compile_all('src', 'target')
+ move_css(".")
+ compress_files("target")
+
+ os.chdir(original_path)
+
+
+if __name__ == '__main__':
+ main()