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