Nav
docforge.nav
Navigation layer for doc-forge.
The docforge.nav package manages the relationship between the logical
documentation structure defined by the user and the physical documentation
files generated on disk.
Workflow
- Specification – Users define navigation intent in
docforge.nav.yml. - Resolution –
resolve_navexpands patterns and matches them against generated Markdown files. - Emission –
MkDocsNavEmitterconverts the resolved structure into the YAML navigation format required bymkdocs.yml.
This layer separates documentation organization from the underlying source code layout, enabling flexible grouping, ordering, and navigation structures independent of module hierarchy.
Classes
MkDocsNavEmitter
Emit MkDocs navigation structures from resolved navigation data.
The emitter transforms a ResolvedNav object into the YAML-compatible
list structure expected by the MkDocs nav configuration field.
Functions
emit
Generate a navigation structure for mkdocs.yml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nav |
ResolvedNav
|
Resolved navigation data describing documentation groups and their associated Markdown files. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
A list of dictionaries representing the MkDocs navigation layout. |
list[dict[str, Any]]
|
Each dictionary maps a navigation label to a page or a list of |
list[dict[str, Any]]
|
pages. |
NavSpec
Parsed representation of a navigation specification.
A NavSpec describes the intended documentation navigation layout before
it is resolved against the filesystem.
Attributes:
| Name | Type | Description |
|---|---|---|
home |
str | None
|
Relative path to the documentation home page (for example
|
groups |
dict[str, list[str]]
|
Mapping of navigation group titles to lists of file patterns or glob expressions. |
icon |
Optional mapping of theme icon entries (for example
|
Initialize a NavSpec instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
home |
str | None
|
Relative path to the home document. |
required |
groups |
dict[str, list[str]]
|
Mapping of group names to lists of path patterns (glob expressions). |
required |
icon |
dict[str, str] | None
|
Optional mapping of theme icon entries applied to the generated MkDocs configuration. |
None
|
Functions
all_patterns
Return all path patterns referenced by the specification.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list containing the home document (if defined) and all |
list[str]
|
group pattern entries. |
load
classmethod
Load a navigation specification from a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
Path
|
Filesystem path to the navigation specification file. |
required |
Returns:
| Type | Description |
|---|---|
NavSpec
|
A |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified file does not exist. |
ValueError
|
If the file contents are not a valid navigation specification. |
ResolvedNav
Resolved navigation structure.
A ResolvedNav represents navigation data after glob patterns have been
expanded and paths validated against the filesystem.
Attributes:
| Name | Type | Description |
|---|---|---|
home |
str | None
|
Relative path to the documentation home page. |
groups |
dict[str, list[Path]]
|
Mapping of navigation group titles to lists of resolved documentation file paths. |
Initialize a ResolvedNav instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
home |
str | None
|
Relative path to the home page within the documentation root. |
required |
groups |
dict[str, list[Path]]
|
Mapping of group titles to resolved documentation file paths. |
required |
docs_root |
Path | None
|
Root directory of the documentation source files. |
None
|
Functions
all_files
Iterate over all files referenced by the navigation structure.
Returns:
| Type | Description |
|---|---|
Iterable[Path]
|
An iterable of |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the home page is defined but the documentation root is not available for resolution. |
Functions
build_wiki_nav
Derive an MkDocs navigation block from a wiki directory.
Returned paths are relative to the parent of wiki_dir and carry the
wiki directory name as their leading component (for example
wiki/01_overview.md when the wiki lives at docs/wiki). This makes
the result directly usable in an MkDocs nav block with
index.mdat the wiki root becomes theHomeentry.- Page labels are derived from filenames: numeric order prefixes such as
01_or02-are stripped, separators are replaced with spaces, and names are title-cased (01_overview.mdbecomesOverview). - Subdirectories become nested navigation groups. A nested
index.mdis rendered as the section root placed first inside the group. - Only
.mdfiles are considered; hidden entries are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wiki_dir |
Path
|
Path to the hand-written wiki directory, for example |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List[Dict[str, Any]]:
Navigation entries compatible with the MkDocs |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the wiki directory does not exist. |
load_nav_spec
Load a navigation specification file.
This helper function reads a YAML navigation file and constructs a
corresponding NavSpec instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
Path
|
Path to the navigation specification file. |
required |
Returns:
| Type | Description |
|---|---|
NavSpec
|
A |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specification file does not exist. |
ValueError
|
If the YAML structure is invalid. |
resolve_nav
Resolve a navigation specification against the filesystem.
The function expands glob patterns defined in a NavSpec and verifies
that referenced documentation files exist within the documentation root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec |
NavSpec
|
Navigation specification describing documentation layout. |
required |
docs_root |
Path
|
Root directory containing documentation Markdown files. |
required |
Returns:
| Type | Description |
|---|---|
ResolvedNav
|
A |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the documentation root does not exist or a navigation pattern does not match any files. |