Skip to content

preview

nbdev_mkdocs.mkdocs.preview(root_path: str, use_relative_doc_links: bool, port: Optional[int] = None) -> None ¤

Preview the mkdocs documentation.

Parameters:

Name Type Description Default
root_path str

The root path of the documentation.

required
use_relative_doc_links bool

If set to True, relative links are added to symbol references in generated documentation. Else, the value set in doc_host in settings.ini is added to symbol references in generated documentation.

required
port Optional[int]

The port to serve the documentation on.

None

Note

The above docstring is autogenerated by docstring-gen library (https://github.com/airtai/docstring-gen)

Source code in nbdev_mkdocs/mkdocs.py
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
def preview(
    root_path: str, use_relative_doc_links: bool, port: Optional[int] = None
) -> None:
    """Preview the mkdocs documentation.

    Args:
        root_path: The root path of the documentation.
        use_relative_doc_links: If set to True, relative links are added to symbol references in generated
            documentation. Else, the value set in doc_host in settings.ini is added to symbol references in
            generated documentation.
        port: The port to serve the documentation on.

    !!! note

        The above docstring is autogenerated by docstring-gen library (https://github.com/airtai/docstring-gen)
    """
    with set_cwd(root_path):
        prepare(
            root_path=root_path,
            use_relative_doc_links=use_relative_doc_links,
            no_test=True,
            no_mkdocs_build=True,
        )

        cmd = f"mkdocs serve -f {root_path}/mkdocs/mkdocs.yml -a 0.0.0.0"
        if port:
            cmd = cmd + f":{port}"

        with subprocess.Popen(  # nosec B603:subprocess_without_shell_equals_true
            shlex.split(cmd),
            stdout=subprocess.PIPE,
            bufsize=1,
            text=True,
            universal_newlines=True,
        ) as p:
            for line in p.stdout:  # type: ignore
                print(line, end="")

        if p.returncode != 0:
            typer.secho(
                f"Command cmd='{cmd}' failed!",
                err=True,
                fg=typer.colors.RED,
            )
            raise typer.Exit(6)