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, output=(root / "public").resolve() if not output else output,
) )
if validate: if validate:
for path in [layout.content, layout.templates]: if not layout.content.is_dir():
if not path.is_dir(): raise FileNotFoundError("Missing required content directory!")
raise FileNotFoundError( if not layout.templates.is_dir():
f"Missing required directory: {path}" # use the included defaults
) layout.templates = util.get_resource_dir("templates")
return layout return layout

View file

@ -25,6 +25,14 @@ def get_resources(subdir: str) -> list[ZonaResource]:
return out 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): def ensure_parents(target: Path):
"""Ensure the target's parent directories exist.""" """Ensure the target's parent directories exist."""
target.parent.mkdir(parents=True, exist_ok=True) target.parent.mkdir(parents=True, exist_ok=True)