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:
parent
2f952af4a7
commit
4f03ca05d9
8 changed files with 228 additions and 60 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue