1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-08 19:46:06 +01:00
nixvim/docs/modules/category.nix
Matt Sturgeon 4f03ca05d9 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).
2025-09-30 16:21:23 +00:00

89 lines
2.2 KiB
Nix

{
lib,
name,
config,
options,
...
}:
let
cfg = config._category;
pageType = lib.types.submoduleWith {
modules = [ ./page.nix ];
};
pages = builtins.removeAttrs config (builtins.attrNames options);
in
{
freeformType = lib.types.attrsOf pageType;
options._category = {
name = lib.mkOption {
type = lib.types.str;
default = name;
defaultText = lib.literalMD "attribute name";
};
order = lib.mkOption {
type = lib.types.int;
default = 100;
description = "Priority for where this category will appear in the menu.";
};
type = lib.mkOption {
type = lib.types.enum [
"prefix"
"normal"
"suffix"
];
default = "normal";
description = ''
The kind of mdbook chapters this category contains.
**Prefix Chapter**
: Before the main numbered chapters, prefix chapters can be added that
will not be numbered. This is useful for forewords, introductions, etc.
There are, however, some constraints.
Prefix chapters cannot be nested; they should all be on the root level.
And you cannot add prefix chapters once you have added numbered chapters.
**Normal Chapter**
: Called a "Numbered Chapter" in the MDBook docs.
Numbered chapters outline the main content of the book and can be
nested, resulting in a nice hierarchy (chapters, sub-chapters, etc.).
**Suffix Chapter**
: Like prefix chapters, suffix chapters are unnumbered, but they come
after numbered chapters.
See <https://rust-lang.github.io/mdBook/format/summary.html>.
'';
};
text = lib.mkOption {
type = lib.types.str;
description = "The rendered menu.";
readOnly = true;
};
};
config._category = {
text = lib.optionalString (pages != { }) ''
# ${cfg.name}
${lib.pipe pages [
builtins.attrValues
(map (
page:
page._page.toMenu {
nested = cfg.type == "normal";
indent = "";
prefix = [ ];
inherit page;
}
))
(builtins.concatStringsSep "\n")
]}
'';
};
}