docs/modules: propagate collections of page nodes
This commit is contained in:
parent
2ab9e79e92
commit
79df3b165c
4 changed files with 38 additions and 20 deletions
|
|
@ -15,22 +15,10 @@ let
|
|||
];
|
||||
};
|
||||
cfg = menuConfiguration.config;
|
||||
pages = cfg.functions;
|
||||
|
||||
# Collect all page nodes into a list of page entries
|
||||
collectPages =
|
||||
pages:
|
||||
builtins.concatMap (
|
||||
node:
|
||||
let
|
||||
children = removeAttrs node [ "_page" ];
|
||||
in
|
||||
lib.optional (node ? _page) node._page ++ lib.optionals (children != { }) (collectPages children)
|
||||
) (builtins.attrValues (removeAttrs pages [ "_category" ]));
|
||||
|
||||
# Normalised page specs
|
||||
pageList = collectPages pages;
|
||||
pagesToRender = builtins.filter (page: page.target != "") pageList;
|
||||
# Page specs
|
||||
inherit (cfg._menu) pages;
|
||||
pagesToRender = builtins.filter (page: page.target != "") pages;
|
||||
|
||||
# Function(s) to render page sections
|
||||
renderSection = {
|
||||
|
|
@ -78,7 +66,7 @@ let
|
|||
inherit lib;
|
||||
rootPath = nixvim;
|
||||
functionSet = lib.extend nixvim.lib.overlay;
|
||||
pathsToScan = lib.pipe pageList [
|
||||
pathsToScan = lib.pipe pages [
|
||||
(lib.concatMap (page: page.content))
|
||||
(lib.catAttrs "functions")
|
||||
(map (x: x.loc))
|
||||
|
|
|
|||
|
|
@ -65,6 +65,12 @@ in
|
|||
description = "The rendered menu.";
|
||||
readOnly = true;
|
||||
};
|
||||
|
||||
pages = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.raw;
|
||||
description = "All pages in the category.";
|
||||
readOnly = true;
|
||||
};
|
||||
};
|
||||
|
||||
config._category = {
|
||||
|
|
@ -85,5 +91,7 @@ in
|
|||
(builtins.concatStringsSep "\n")
|
||||
]}
|
||||
'';
|
||||
|
||||
pages = lib.concatMap (x: x._page.pages) (builtins.attrValues pages);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
categories = removeAttrs config (builtins.attrNames options);
|
||||
categories = lib.pipe options [
|
||||
builtins.attrNames
|
||||
(removeAttrs config)
|
||||
builtins.attrValues
|
||||
(map (x: x._category))
|
||||
(lib.sortOn (x: x.order))
|
||||
];
|
||||
in
|
||||
{
|
||||
options._menu = {
|
||||
|
|
@ -14,13 +20,15 @@ in
|
|||
description = "The rendered menu.";
|
||||
readOnly = true;
|
||||
};
|
||||
pages = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.raw;
|
||||
description = "All pages in the menu.";
|
||||
readOnly = true;
|
||||
};
|
||||
};
|
||||
|
||||
config._menu = {
|
||||
text = lib.pipe categories [
|
||||
builtins.attrValues
|
||||
(map (x: x._category))
|
||||
(lib.sortOn (x: x.order))
|
||||
(builtins.groupBy (x: x.type))
|
||||
(
|
||||
{
|
||||
|
|
@ -33,5 +41,6 @@ in
|
|||
(map (x: x.text))
|
||||
(builtins.concatStringsSep "\n\n")
|
||||
];
|
||||
pages = lib.concatMap (x: x.pages) categories;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,6 +115,11 @@ in
|
|||
'';
|
||||
readOnly = true;
|
||||
};
|
||||
pages = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.raw;
|
||||
description = "This page, its children, their children, etc.";
|
||||
readOnly = true;
|
||||
};
|
||||
};
|
||||
|
||||
config._page = {
|
||||
|
|
@ -122,5 +127,13 @@ in
|
|||
inherit lib;
|
||||
optionNames = builtins.attrNames options;
|
||||
};
|
||||
|
||||
pages = lib.pipe options [
|
||||
builtins.attrNames
|
||||
(removeAttrs config)
|
||||
builtins.attrValues
|
||||
(lib.concatMap (x: x._page.pages))
|
||||
(children: [ cfg ] ++ children)
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue