mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-09 03:56:05 +01:00
31 lines
936 B
Nix
31 lines
936 B
Nix
{
|
|
lib,
|
|
pages,
|
|
indentSize ? " ",
|
|
}:
|
|
let
|
|
pageToLines =
|
|
indent: parent: node:
|
|
let
|
|
|
|
children = lib.pipe node [
|
|
(lib.flip builtins.removeAttrs [ "_page" ])
|
|
builtins.attrValues
|
|
];
|
|
# Only add node to the menu if it has content or multiple children
|
|
useNodeInMenu = node._page.target != "" || node._page.children > 1;
|
|
nextParent = if useNodeInMenu then node else parent;
|
|
nextIndent = if useNodeInMenu then indent + indentSize else indent;
|
|
loc = lib.lists.removePrefix (parent._page.loc or [ ]) node._page.loc;
|
|
menuName = lib.attrsets.showAttrPath loc;
|
|
in
|
|
lib.optional useNodeInMenu "${indent}- [${menuName}](${node._page.target})"
|
|
++ lib.optionals (children != [ ]) (
|
|
builtins.concatMap (pageToLines nextIndent nextParent) children
|
|
);
|
|
in
|
|
lib.pipe pages [
|
|
builtins.attrValues
|
|
(builtins.concatMap (pageToLines "" null))
|
|
lib.concatLines
|
|
]
|