diff --git a/src/zona/builder.py b/src/zona/builder.py index 3ad692a..ac1a5e7 100644 --- a/src/zona/builder.py +++ b/src/zona/builder.py @@ -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): diff --git a/src/zona/cli.py b/src/zona/cli.py index 9ca7c1f..8ecaaf1 100644 --- a/src/zona/cli.py +++ b/src/zona/cli.py @@ -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() diff --git a/src/zona/config.py b/src/zona/config.py index 47a4961..b735c85 100644 --- a/src/zona/config.py +++ b/src/zona/config.py @@ -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 diff --git a/src/zona/metadata.py b/src/zona/metadata.py index 1ec98ab..eaa6315 100644 --- a/src/zona/metadata.py +++ b/src/zona/metadata.py @@ -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: diff --git a/src/zona/server.py b/src/zona/server.py index e4a7cbd..e2b266e 100644 --- a/src/zona/server.py +++ b/src/zona/server.py @@ -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