feat: clean output directory on build

This commit is contained in:
Daniel Fichtinger 2025-07-12 00:43:53 -04:00
parent 71e541aa5e
commit 8793284bd6
2 changed files with 10 additions and 4 deletions

View file

@ -1,3 +1,4 @@
import shutil
from datetime import date from datetime import date
from pathlib import Path from pathlib import Path
@ -50,9 +51,7 @@ class ZonaBuilder:
if path.name.endswith(".md") and not path.is_relative_to( if path.name.endswith(".md") and not path.is_relative_to(
layout.root / "content" / "static" layout.root / "content" / "static"
): ):
logger.debug( logger.debug(f"Parsing {path.name}.")
f"Parsing {path.name} as Markdown document."
)
item.metadata, item.content = parse_metadata(path) item.metadata, item.content = parse_metadata(path)
if ( if (
item.metadata.draft item.metadata.draft
@ -140,6 +139,13 @@ class ZonaBuilder:
util.copy_static_file(item.source, dst) util.copy_static_file(item.source, dst)
def build(self): def build(self):
# clean output if applicable
if (
self.config.build.clean_output_dir
and self.layout.output.is_dir()
):
logger.debug("Removing stale output...")
shutil.rmtree(self.layout.output)
logger.debug("Discovering...") logger.debug("Discovering...")
self._discover() self._discover()
logger.debug("Building...") logger.debug("Building...")

View file

@ -54,7 +54,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