Skip to content

serve

Class info

🛈 DocStrings

catch_exceptions

catch_exceptions(config: MkNodesConfig)

Context manager used to clean up in case of build error.

Parameters:

Name Type Description Default
config MkNodesConfig

Build config.

required
Source code in mkdocs_mknodes/commands/serve.py
51
52
53
54
55
56
57
58
59
60
61
62
63
@contextlib.contextmanager
def catch_exceptions(config: mknodesconfig.MkNodesConfig):
    """Context manager used to clean up in case of build error.

    Args:
        config: Build config.
    """
    try:
        yield
    finally:
        config.plugins.on_shutdown()
        if pathlib.Path(config.site_dir).is_dir():
            shutil.rmtree(config.site_dir)

serve

serve(
    config_path: str | PathLike[str] = CFG_DEFAULT,
    theme: str | None = None,
    **kwargs: Any
)

Serve a MkNodes-based website.

Parameters:

Name Type Description Default
config_path str | PathLike[str]

The path to the config file to use

CFG_DEFAULT
repo_path

Path to the repository a page should be built for

required
build_fn

Callable to use for creating the webpage

required
clone_depth

If repository is remote, the amount of commits to fetch

required
theme str | None

Theme to use

None
kwargs Any

Optional config values (overrides value from config)

{}
Source code in mkdocs_mknodes/commands/serve.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def serve(
    config_path: str | os.PathLike[str] = paths.CFG_DEFAULT,
    theme: str | None = None,
    **kwargs: Any,
):
    """Serve a MkNodes-based website.

    Args:
        config_path: The path to the config file to use
        repo_path: Path to the repository a page should be built for
        build_fn: Callable to use for creating the webpage
        clone_depth: If repository is remote, the amount of commits to fetch
        theme: Theme to use
        kwargs: Optional config values (overrides value from config)
    """
    if theme and theme != "material":
        kwargs["theme"] = theme
    text = upath.UPath(config_path).read_text()
    stream = io.StringIO(text)
    stream.name = str(config_path)
    _serve(config_file=stream, livereload=False, **kwargs)  # type: ignore[arg-type]