diff --git a/mkdocs_mknodes/appconfig/appconfig.py b/mkdocs_mknodes/appconfig/appconfig.py index 8c7950b..36866d8 100644 --- a/mkdocs_mknodes/appconfig/appconfig.py +++ b/mkdocs_mknodes/appconfig/appconfig.py @@ -16,6 +16,7 @@ ) from pydantic.functional_validators import BeforeValidator from pydantic_core import PydanticCustomError +import upath from mkdocs_mknodes.appconfig import jinjaconfig, themeconfig, validationconfig from mkdocs_mknodes.appconfig.base import ConfigFile @@ -261,7 +262,7 @@ class AppConfig(ConfigFile): """ repo_path: str = "." """Path to the repository to create a website for. (`http://....my_project.git`)""" - clone_depth: int = 100 + clone_depth: int | None = 100 """Clone depth in case the repository is remote. (Required for `git-changelog`).""" build_folder: str | None = None """Folder to create the Markdown files in. @@ -318,7 +319,7 @@ class AppConfig(ConfigFile): Allows setting up loaders, extensions and the render behavior. """ - docs_dir: DirectoryPath = Field("docs") + docs_dir: str = Field("docs/") """Directory containing documentation markdown source files. !!! info "Path Resolution" @@ -772,6 +773,16 @@ def validate_nav( return [] return values + @field_validator("docs_dir", mode="before") + @classmethod + def validate_docs_dir(cls, value: str, info: ValidationInfo) -> str: + config_file_path = info.data["config_file_path"] + config_dir = upath.UPath(config_file_path).parent if config_file_path else None + path = upath.UPath(value) + if config_dir and not path.is_absolute(): + path = config_dir / path + return str(path.resolve()) + @field_validator("dev_addr", mode="before") @classmethod def validate_ip_port(cls, v: str) -> str: diff --git a/mkdocs_mknodes/builders/configbuilder.py b/mkdocs_mknodes/builders/configbuilder.py index 96e6a4a..7c390a7 100644 --- a/mkdocs_mknodes/builders/configbuilder.py +++ b/mkdocs_mknodes/builders/configbuilder.py @@ -44,7 +44,7 @@ def build_mkdocs_config( if self.clone_depth is not None: cfg.clone_depth = self.clone_depth # cfg = {**cfg, **kwargs} - text = yamling.dump_yaml(cfg.model_dump(mode="json")) + text = yamling.dump_yaml(cfg.model_dump(mode="json", exclude_none=True)) buffer = io.StringIO(text) buffer.name = cfg.config_file_path config = mknodesconfig.MkNodesConfig.from_yaml(buffer, **kwargs)