Skip to content

MkNodes site generator

Overview

MkDocs-MkNodes turns MkNodes node trees into websites.

MkNodes is a library to create complex documentation websites. It includes a powerful jinja environment to assist in writing Markdown text as well as a a large set of so-called MkNodes, which can be used to create re-usable node trees describing a complete website. That node tree covers the whole site navigation, down to single Markdown elements, allowing the creator anytime to switch between programatically creating documentation and writing Markdown "by hand".

This package is the site generator: it runs a build function, collects pages, navigation, assets, template overrides and the required Markdown extensions from the node tree and writes them as input for Zensical, which builds the HTML website.

Info

Still sounds confusing? The best way to learn how everything works is to start with the MkNodes documentation.

In addition, all pages on this website include an Admonition box at the bottom, which also includes the code which generated the page. That might be a helpful resource to understand how MkNodes can be used.

Two ways to use it

1. Zero configuration. Just run

mkdocs-mknodes build

in a repository (with or without a mkdocs.yml for theme and site settings). This creates a default website for the project: the README.md as index page, API docs, CLI docs (if the project has a CLI) and a "Development" section with changelog, contribution guidelines, dependencies and license.

2. Your own build function. Point build-fn to a callable which populates the root nav:

# pyproject.toml
[tool.mknodes]
build-fn = "build_docs.py:build"
import mknodes as mk


def build(root: mk.MkNav, theme: mk.Theme) -> None:
    page = root.add_page("Home", is_index=True, hide="toc")
    page += mk.MkAdmonition("Hello world!")
    root.add_doc(section_name="API", recursive=True)

The build function gets called with the keyword arguments root and theme (plus everything set via the kwargs setting) and may also be async. Alternatively, the default build function mkdocs_mknodes:parse accepts a node tree written in YAML / TOML via the pages setting (see the use cases section).

Hand-written Markdown pages in the docs folder keep working next to the generated ones (a nav in mkdocs.yml comes first, the generated nav gets appended).

Page info
Code for this page
mkdocs_mknodes.manual.get_started_section._
@router.route_page("MkNodes site generator", hide="toc", is_homepage=True)
def _(page: mk.MkPage):
    page += mk.MkTemplate("index.jinja")
Resources
Resources(css=[],
          markdown_extensions={},
          plugins=[],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mkdocs-mknodes/mkdocs-mknodes/mkdocs_mknodes/manual/root.py
  source_function: Build.on_root
  source_line_no: 24
hide:
- toc
title: MkNodes site generator