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
77
78
79
80
81
82
83
84
85
86
87
88
89
@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,
    repo_path: str = ".",
    build_fn: str = DEFAULT_BUILD_FN,
    clone_depth: int = 100,
    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 str

Path to the repository a page should be built for

'.'
build_fn str

Callable to use for creating the webpage

DEFAULT_BUILD_FN
clone_depth int

If repository is remote, the amount of commits to fetch

100
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
49
50
51
52
53
54
55
56
57
58
59
def serve(
    config_path: str | os.PathLike[str] = paths.CFG_DEFAULT,
    repo_path: str = ".",
    build_fn: str = paths.DEFAULT_BUILD_FN,
    clone_depth: int = 100,
    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)
    """
    config = mkdocsconfigfile.MkDocsConfigFile(config_path)
    config.update_mknodes_section(
        repo_url=repo_path,
        build_fn=build_fn,
        clone_depth=clone_depth,
    )
    if theme and theme != "material":
        config.remove_plugin("social")
        config.remove_plugin("tags")
        kwargs["theme"] = theme
    text = yamling.dump_yaml(dict(config))
    stream = io.StringIO(text)
    stream.name = str(config_path)
    _serve(config_file=stream, livereload=False, **kwargs)  # type: ignore[arg-type]