1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-12-14 21:11:09 +01:00

docs/lib: generalise menu impl using module system

Move the mdbook menu rendering code into the module system and
generalise it to apply to multiple "categories" (mdbook parts) and
"types" of category (prefix, suffix, etc).
This commit is contained in:
Matt Sturgeon 2025-09-23 18:25:39 +01:00
parent 2f952af4a7
commit 4f03ca05d9
8 changed files with 228 additions and 60 deletions

View file

@ -10,19 +10,14 @@
}:
let
pageConfiguration = lib.evalModules {
menuConfiguration = lib.evalModules {
modules = [
pageSpecs
{
freeformType = lib.types.attrsOf (
lib.types.submoduleWith {
modules = [ ../modules/page.nix ];
}
);
}
../modules/menu.nix
];
};
pages = pageConfiguration.config;
cfg = menuConfiguration.config;
pages = cfg.functions;
# Collect all page nodes into a list of page entries
collectPages =
@ -33,7 +28,7 @@ let
children = builtins.removeAttrs node [ "_page" ];
in
lib.optional (node ? _page) node._page ++ lib.optionals (children != { }) (collectPages children)
) (builtins.attrValues pages);
) (builtins.attrValues (builtins.removeAttrs pages [ "_category" ]));
# Normalised page specs
pageList = collectPages pages;
@ -60,11 +55,9 @@ let
}
);
passthru.config = pageConfiguration;
passthru.config = menuConfiguration;
passthru.menu = import ./menu.nix {
inherit lib pages;
};
passthru.menu = cfg._menu.text;
passthru.pages = map (page: "${result}/${page.target}") pagesToRender;
}