Add Directory(Output) class to create and track directories
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
from omicron.ssg.output.output import Output
|
||||
from pathlib import Path
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from omicron.ssg.site import Site # for static checking with mypy
|
||||
else:
|
||||
Site = "omicron.ssg.site.Site" # for runtime checking with beartype
|
||||
|
||||
|
||||
class Directory(Output):
|
||||
def __init__(self, site: Site, destination: Path):
|
||||
super().__init__(site, destination)
|
||||
url_path = Path("/") / site.base_dir / destination
|
||||
# rebuild url because Output strips /index.html which is a valid dir
|
||||
self.url = url_path.as_posix()
|
||||
|
||||
def write(self) -> None:
|
||||
dest = self.site.output_path / self.destination
|
||||
dest.mkdir(parents=True, exist_ok=True)
|
||||
log.debug("Created directory %s", dest)
|
||||
Reference in New Issue
Block a user