Added live serving

This commit is contained in:
Christoph Stahl 2025-07-20 12:44:48 +02:00
parent fed3e3f586
commit ca0b2e7c5b

View file

@ -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()