Skip to content

cli

Class info

🛈 DocStrings

MkDocs-MkNodes CLI interface.

build

build(
    repo_path: str = Option(None, *REPO_CMDS, help=REPO_HELP, show_default=False),
    build_fn: str = Option(None, *BUILD_CMS, help=BUILD_HELP, show_default=False),
    site_dir: str = Option("site", *SITE_DIR_CMDS, help=SITE_DIR_HELP),
    clone_depth: int = Option(None, *DEPTH_CMDS, help=DEPTH_HELP, show_default=False),
    config_path: str = Option(CFG_DEFAULT, *CFG_PATH_CMDS, help=CFG_PATH_HELP),
    theme: str = Option("material", *THEME_CMDS, help=THEME_HELP),
    strict: bool = Option(False, *STRICT_CMDS, help=STRICT_HELP),
    use_directory_urls: bool = Option(True, *USE_DIR_URLS_CMDS, help=USE_DIR_URLS_HELP),
    _verbose: bool = Option(False, *VERBOSE_CMDS, help=VERBOSE_HELP, callback=verbose),
    _quiet: bool = Option(False, *QUIET_CMDS, help=QUIET_HELP, callback=quiet),
)

Create a MkNodes-based website, locally or remotely.

Runs the build script on given repository (either locally or a hosted one), adapts the config file automatically and creates the HTML website in given site dir.

Further info here: https://phil65.github.io/mkdocs-mknodes/CLI/

Source code in mkdocs_mknodes/cli/__init__.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@cli.command()
def build(
    repo_path: str = t.Option(None, *REPO_CMDS, help=REPO_HELP, show_default=False),
    build_fn: str = t.Option(None, *BUILD_CMS, help=BUILD_HELP, show_default=False),
    site_dir: str = t.Option("site", *SITE_DIR_CMDS, help=SITE_DIR_HELP),
    clone_depth: int = t.Option(None, *DEPTH_CMDS, help=DEPTH_HELP, show_default=False),
    config_path: str = t.Option(paths.CFG_DEFAULT, *CFG_PATH_CMDS, help=CFG_PATH_HELP),
    theme: str = t.Option("material", *THEME_CMDS, help=THEME_HELP),
    strict: bool = t.Option(False, *STRICT_CMDS, help=STRICT_HELP),
    use_directory_urls: bool = t.Option(True, *USE_DIR_URLS_CMDS, help=USE_DIR_URLS_HELP),
    _verbose: bool = t.Option(False, *VERBOSE_CMDS, help=VERBOSE_HELP, callback=verbose),
    _quiet: bool = t.Option(False, *QUIET_CMDS, help=QUIET_HELP, callback=quiet),
):
    """Create a MkNodes-based website, locally or remotely.

    Runs the build script on given repository (either locally or a hosted one), adapts
    the config file automatically and creates the HTML website in given site dir.

    Further info here: https://phil65.github.io/mkdocs-mknodes/CLI/
    """
    build_page.build(
        config_path=config_path,
        repo_path=repo_path,
        build_fn=build_fn,
        clone_depth=clone_depth,
        site_dir=site_dir,
        strict=strict,
        theme=theme if theme != "material" else None,
        use_directory_urls=use_directory_urls,
    )

create_config

create_config(
    repo_path: str = Option(None, *REPO_CMDS, help=REPO_HELP, show_default=False),
    build_fn: str = Option(None, *BUILD_CMS, help=BUILD_HELP, show_default=False),
    theme: str = Option("material", *THEME_CMDS, help=THEME_HELP),
    use_directory_urls: bool = Option(True, *USE_DIR_URLS_CMDS, help=USE_DIR_URLS_HELP),
    _verbose: bool = Option(False, *VERBOSE_CMDS, help=VERBOSE_HELP, callback=verbose),
    _quiet: bool = Option(False, *QUIET_CMDS, help=QUIET_HELP, callback=quiet),
)

Create a config based on a given build setup.

Runs the build script on given repository (either locally or a hosted one), infers the required resources (CSS / JS / Md extensions) as well as metadata and creates a MkDocs config file.

Further info here: https://phil65.github.io/mkdocs-mknodes/CLI/

Source code in mkdocs_mknodes/cli/__init__.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
@cli.command()
def create_config(
    repo_path: str = t.Option(None, *REPO_CMDS, help=REPO_HELP, show_default=False),
    build_fn: str = t.Option(None, *BUILD_CMS, help=BUILD_HELP, show_default=False),
    # config_path: str = t.Option(paths.CFG_DEFAULT, *CFG_PATH_CMDS, help=CFG_PATH_HELP),
    theme: str = t.Option("material", *THEME_CMDS, help=THEME_HELP),
    use_directory_urls: bool = t.Option(True, *USE_DIR_URLS_CMDS, help=USE_DIR_URLS_HELP),
    _verbose: bool = t.Option(False, *VERBOSE_CMDS, help=VERBOSE_HELP, callback=verbose),
    _quiet: bool = t.Option(False, *QUIET_CMDS, help=QUIET_HELP, callback=quiet),
):
    """Create a config based on a given build setup.

    Runs the build script on given repository (either locally or a hosted one),
    infers the required resources (CSS / JS / Md extensions) as well as metadata
    and creates a MkDocs config file.

    Further info here: https://phil65.github.io/mkdocs-mknodes/CLI/
    """
    build_fn = build_fn or paths.DEFAULT_BUILD_FN

    config = appconfig.AppConfig.from_yaml_file(paths.RESOURCES / "mkdocs_basic.yml")
    theme_name = theme or "material"
    if theme_name != "material":
        theme_dict = dict(name=theme_name, override_dir="overrides")
        config.set_theme(theme_dict)
    config.use_directory_urls = use_directory_urls
    skin = mk.Theme(theme_name)
    nav = mk.MkNav.with_context(repo_url=repo_path)
    builder = classhelpers.to_callable(build_fn)
    builder(context=nav.ctx)
    collector = buildcollector.BuildCollector([])
    info = collector.collect(nav, skin)
    resources = info.resources
    info = nav.ctx.metadata
    if social := info.social_info:
        config.extra["social"] = social  # type: ignore[index]
    config.markdown_extensions = resources.markdown_extensions
    config.repo_path = info.repository_url
    config.site_description = info.summary
    config.site_name = info.distribution_name
    config.site_author = info.author_name
    config.copyright = f"Copyright © {datetime.now().year} {info.author_name}"
    result = yamling.dump_yaml(
        config.model_dump(exclude_unset=True, exclude_defaults=True)
    )
    print(result)

serve

serve(
    repo_path: str = Option(None, *REPO_CMDS, help=REPO_HELP, show_default=False),
    build_fn: str = Option(None, *BUILD_CMS, help=BUILD_HELP, show_default=False),
    clone_depth: int = Option(None, *DEPTH_CMDS, help=DEPTH_HELP, show_default=False),
    config_path: str = Option(CFG_DEFAULT, *CFG_PATH_CMDS, help=CFG_PATH_HELP),
    strict: bool = Option(False, *STRICT_CMDS, help=STRICT_HELP),
    theme: str = Option("material", *THEME_CMDS, help=THEME_HELP),
    use_directory_urls: bool = Option(True, *USE_DIR_URLS_CMDS, help=USE_DIR_URLS_HELP),
    _verbose: bool = Option(False, *VERBOSE_CMDS, help=VERBOSE_HELP, callback=verbose),
    _quiet: bool = Option(False, *QUIET_CMDS, help=QUIET_HELP, callback=quiet),
)

Serve a MkNodes-based website, locally or remotely.

Runs the build script on given repository (either locally or a hosted one), adapts the config file automatically and serves a webpage on http://127.0.0.1/8000/.

Further info here: https://phil65.github.io/mkdocs-mknodes/CLI/

Source code in mkdocs_mknodes/cli/__init__.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@cli.command()
def serve(
    repo_path: str = t.Option(None, *REPO_CMDS, help=REPO_HELP, show_default=False),
    build_fn: str = t.Option(None, *BUILD_CMS, help=BUILD_HELP, show_default=False),
    clone_depth: int = t.Option(None, *DEPTH_CMDS, help=DEPTH_HELP, show_default=False),
    config_path: str = t.Option(paths.CFG_DEFAULT, *CFG_PATH_CMDS, help=CFG_PATH_HELP),
    strict: bool = t.Option(False, *STRICT_CMDS, help=STRICT_HELP),
    theme: str = t.Option("material", *THEME_CMDS, help=THEME_HELP),
    use_directory_urls: bool = t.Option(True, *USE_DIR_URLS_CMDS, help=USE_DIR_URLS_HELP),
    _verbose: bool = t.Option(False, *VERBOSE_CMDS, help=VERBOSE_HELP, callback=verbose),
    _quiet: bool = t.Option(False, *QUIET_CMDS, help=QUIET_HELP, callback=quiet),
):
    """Serve a MkNodes-based website, locally or remotely.

    Runs the build script on given repository (either locally or a hosted one), adapts
    the config file automatically and serves a webpage on http://127.0.0.1/8000/.

    Further info here: https://phil65.github.io/mkdocs-mknodes/CLI/
    """
    serve_.serve(
        config_path=config_path,
        build_fn=build_fn,
        repo_path=repo_path,
        clone_depth=clone_depth,
        strict=strict,
        theme=theme if theme != "material" else None,
        use_directory_urls=use_directory_urls,
    )