diff --git a/build.py b/build.py index def469c..964ec41 100644 --- a/build.py +++ b/build.py @@ -3,6 +3,8 @@ import shutil from dataclasses import dataclass import markdown from jinja2 import Environment, FileSystemLoader +import sys +from http.server import SimpleHTTPRequestHandler, HTTPServer @dataclass @@ -49,6 +51,18 @@ class Section: def main() -> None: + if sys.argv[1:] and sys.argv[1] == "serve": + port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000 + os.chdir("dist") + print(f"Serving on http://localhost:{port}") + httpd = HTTPServer(("localhost", port), SimpleHTTPRequestHandler) + try: + httpd.serve_forever() + except KeyboardInterrupt: + print("\nServer stopped.") + finally: + httpd.server_close() + return env = Environment(loader=FileSystemLoader(".")) template = env.get_template("site.template.html") @@ -70,6 +84,9 @@ def main() -> None: shutil.rmtree(dst_folder, ignore_errors=True) shutil.copytree(src_folder, dst_folder) + if os.path.exists("favicon.ico"): + shutil.copy("favicon.ico", "dist/favicon.ico") + if __name__ == "__main__": main()