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

View file

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

View file

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

View file

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

View file

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