added drafts

This commit is contained in:
Daniel Fichtinger 2025-07-04 13:22:39 -04:00
parent 4eb2390707
commit 9f38b16d0c
5 changed files with 28 additions and 6 deletions

View file

@ -18,12 +18,15 @@ class ZonaBuilder:
self,
cli_root: Path | None = None,
cli_output: Path | None = None,
draft: bool = False,
):
logger.debug("Initializing ZonaBuilder.")
self.layout: Layout = discover_layout(cli_root, cli_output)
self.config: ZonaConfig = ZonaConfig.from_file(
self.layout.root / "config.yml"
)
if draft:
self.config.build.include_drafts = True
self.items: list[Item] = []
self.item_map: dict[Path, Item] = {}
@ -51,6 +54,11 @@ class ZonaBuilder:
f"Parsing {path.name} as Markdown document."
)
item.metadata, item.content = parse_metadata(path)
if (
item.metadata.draft
and not self.config.build.include_drafts
):
continue
if item.metadata.post == True:
item.post = True
elif item.metadata.post is None:
@ -81,7 +89,6 @@ class ZonaBuilder:
"" if rel_url == Path(".") else rel_url.as_posix()
)
items.append(item)
# print(item)
self.items = items
def _build(self):

View file

@ -45,13 +45,19 @@ def build(
"--output", "-o", help="Location to write built website"
),
] = None,
draft: Annotated[
bool,
typer.Option("--draft", "-d", help="Include drafts."),
] = False,
):
"""
Build the website.
Optionally specify the ROOT and OUTPUT directories.
"""
builder = ZonaBuilder(root, output)
if draft:
print("Option override: including drafts.")
builder = ZonaBuilder(cli_root=root, cli_output=output, draft=draft)
builder.build()
@ -69,6 +75,10 @@ def serve(
"--output", "-o", help="Location to write built website"
),
] = None,
draft: Annotated[
bool,
typer.Option("--draft", "-d", help="Include drafts."),
] = False,
):
"""
Build the website and start a live preview server.
@ -77,7 +87,9 @@ def serve(
Optionally specify the ROOT and OUTPUT directories.
"""
server.serve(root, output)
if draft:
print("Option override: including drafts.")
server.serve(root, output, draft)
@app.callback()

View file

@ -45,7 +45,7 @@ class MarkdownConfig:
@dataclass
class BuildConfig:
clean_output_dir: bool = True
# clean_output_dir: bool = True
include_drafts: bool = False
@ -60,7 +60,7 @@ class ZonaConfig:
# list of globs relative to content that should be ignored
ignore: list[str] = field(default_factory=lambda: IGNORELIST)
markdown: MarkdownConfig = field(default_factory=MarkdownConfig)
# build: BuildConfig = field(default_factory=BuildConfig)
build: BuildConfig = field(default_factory=BuildConfig)
blog: BlogConfig = field(default_factory=BlogConfig)
@classmethod

View file

@ -21,6 +21,7 @@ class Metadata:
footer: bool = True
template: str | None = None
post: bool | None = None
draft: bool = False
def parse_date(raw_date: str | date | object) -> date:

View file

@ -1,6 +1,7 @@
import signal
import os
import sys
from rich import print
from types import FrameType
from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler
import threading
@ -70,10 +71,11 @@ def run_http_server(dir: Path, host: str = "localhost", port: int = 8000):
def serve(
root: Path | None = None,
output: Path | None = None,
draft: bool = False,
host: str = "localhost",
port: int = 8000,
):
builder = ZonaBuilder(root, output)
builder = ZonaBuilder(root, output, draft)
builder.build()
if output is None:
output = builder.layout.output