server now builds to tempdir by default
This commit is contained in:
parent
8793284bd6
commit
bdd7558999
2 changed files with 65 additions and 65 deletions
|
@ -59,9 +59,7 @@ def build(
|
|||
"""
|
||||
if draft:
|
||||
print("Option override: including drafts.")
|
||||
builder = ZonaBuilder(
|
||||
cli_root=root, cli_output=output, draft=draft
|
||||
)
|
||||
builder = ZonaBuilder(cli_root=root, cli_output=output, draft=draft)
|
||||
builder.build()
|
||||
|
||||
|
||||
|
@ -75,9 +73,7 @@ def serve(
|
|||
] = None,
|
||||
host: Annotated[
|
||||
str,
|
||||
typer.Option(
|
||||
"--host", help="Hostname for live preview server."
|
||||
),
|
||||
typer.Option("--host", help="Hostname for live preview server."),
|
||||
] = "localhost",
|
||||
port: Annotated[
|
||||
int,
|
||||
|
@ -90,7 +86,9 @@ def serve(
|
|||
output: Annotated[
|
||||
Path | None,
|
||||
typer.Option(
|
||||
"--output", "-o", help="Location to write built website"
|
||||
"--output",
|
||||
"-o",
|
||||
help="Location to write built website. Temporary directory by default.",
|
||||
),
|
||||
] = None,
|
||||
draft: Annotated[
|
||||
|
|
|
@ -2,6 +2,7 @@ import io
|
|||
import os
|
||||
import signal
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
||||
from pathlib import Path
|
||||
|
@ -173,7 +174,9 @@ def serve(
|
|||
live_reload: bool = True,
|
||||
):
|
||||
"""Serve preview website with live reload and automatic rebuild."""
|
||||
builder = ZonaBuilder(root, output, draft)
|
||||
# create temp dir, automatic cleanup
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
builder = ZonaBuilder(root, Path(tmp), draft)
|
||||
# initial site build
|
||||
builder.build()
|
||||
# use discovered paths if none provided
|
||||
|
@ -226,10 +229,9 @@ def serve(
|
|||
|
||||
# function to shut down gracefully
|
||||
def shutdown_handler(_a: int, _b: FrameType | None):
|
||||
logger.info("Shutting down...")
|
||||
print("Shutting down...")
|
||||
observer.stop()
|
||||
httpd.shutdown()
|
||||
sys.exit(0)
|
||||
|
||||
# register shutdown handler
|
||||
signal.signal(signal.SIGINT, shutdown_handler)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue