use packaged templates if none in project

This commit is contained in:
Daniel Fichtinger 2025-06-27 22:44:03 -04:00
parent ca58a0758c
commit acdb42fdb9
2 changed files with 14 additions and 5 deletions

View file

@ -23,11 +23,12 @@ class Layout:
output=(root / "public").resolve() if not output else output,
)
if validate:
for path in [layout.content, layout.templates]:
if not path.is_dir():
raise FileNotFoundError(
f"Missing required directory: {path}"
)
if not layout.content.is_dir():
raise FileNotFoundError("Missing required content directory!")
if not layout.templates.is_dir():
# use the included defaults
layout.templates = util.get_resource_dir("templates")
return layout

View file

@ -25,6 +25,14 @@ def get_resources(subdir: str) -> list[ZonaResource]:
return out
def get_resource_dir(subdir: str) -> Path:
dir = resources.files("zona").joinpath(f"data/{subdir}")
with resources.as_file(dir) as path:
assert isinstance(path, Path)
assert path.is_dir()
return path
def ensure_parents(target: Path):
"""Ensure the target's parent directories exist."""
target.parent.mkdir(parents=True, exist_ok=True)