mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
docs/mdbook: cleanup with lib
This commit is contained in:
parent
9c11b54065
commit
ff042dfc93
1 changed files with 22 additions and 23 deletions
|
@ -7,7 +7,6 @@
|
||||||
hmOptions,
|
hmOptions,
|
||||||
search,
|
search,
|
||||||
}:
|
}:
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
inherit (evaledModules.config.meta) nixvimInfo;
|
inherit (evaledModules.config.meta) nixvimInfo;
|
||||||
|
|
||||||
|
@ -31,17 +30,17 @@ let
|
||||||
removeWhitespace = builtins.replaceStrings [ " " ] [ "" ];
|
removeWhitespace = builtins.replaceStrings [ " " ] [ "" ];
|
||||||
|
|
||||||
getSubOptions =
|
getSubOptions =
|
||||||
opts: path: optionalAttrs (isVisible opts) (removeUnwanted (opts.type.getSubOptions path));
|
opts: path: lib.optionalAttrs (isVisible opts) (removeUnwanted (opts.type.getSubOptions path));
|
||||||
|
|
||||||
isVisible =
|
isVisible =
|
||||||
opts:
|
opts:
|
||||||
if isOption opts then
|
if lib.isOption opts then
|
||||||
opts.visible or true
|
opts.visible or true
|
||||||
else if opts.isOption then
|
else if opts.isOption then
|
||||||
opts.index.options.visible or true
|
opts.index.options.visible or true
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
filterFunc = filterAttrs (_: v: if isAttrs v then isVisible v else true);
|
filterFunc = lib.filterAttrs (_: v: if lib.isAttrs v then isVisible v else true);
|
||||||
|
|
||||||
hasEmptyIndex = (filterFunc opts.index.options) == { };
|
hasEmptyIndex = (filterFunc opts.index.options) == { };
|
||||||
hasEmptyComponents = (filterFunc opts.components) == { };
|
hasEmptyComponents = (filterFunc opts.components) == { };
|
||||||
|
@ -54,11 +53,11 @@ let
|
||||||
if isOpt then
|
if isOpt then
|
||||||
opts
|
opts
|
||||||
else
|
else
|
||||||
filterAttrs (_: component: component.isOption && (isVisible component)) opts;
|
lib.filterAttrs (_: component: component.isOption && (isVisible component)) opts;
|
||||||
path = removeWhitespace (concatStringsSep "/" path);
|
path = removeWhitespace (lib.concatStringsSep "/" path);
|
||||||
moduleDoc =
|
moduleDoc =
|
||||||
let
|
let
|
||||||
info = optionalAttrs (hasAttrByPath path nixvimInfo) (getAttrFromPath path nixvimInfo);
|
info = lib.attrByPath path { } nixvimInfo;
|
||||||
maintainers = lib.unique (evaledModules.config.meta.maintainers.${info.file} or [ ]);
|
maintainers = lib.unique (evaledModules.config.meta.maintainers.${info.file} or [ ]);
|
||||||
maintainersNames = builtins.map maintToMD maintainers;
|
maintainersNames = builtins.map maintToMD maintainers;
|
||||||
maintToMD = m: if m ? github then "[${m.name}](https://github.com/${m.github})" else m.name;
|
maintToMD = m: if m ? github then "[${m.name}](https://github.com/${m.github})" else m.name;
|
||||||
|
@ -85,7 +84,7 @@ let
|
||||||
if isOpt then
|
if isOpt then
|
||||||
{ }
|
{ }
|
||||||
else
|
else
|
||||||
filterAttrs (_: component: !component.isOption && (isVisible component)) opts;
|
lib.filterAttrs (_: component: !component.isOption && (isVisible component)) opts;
|
||||||
|
|
||||||
hasComponents = components != { };
|
hasComponents = components != { };
|
||||||
|
|
||||||
|
@ -100,7 +99,7 @@ let
|
||||||
let
|
let
|
||||||
g =
|
g =
|
||||||
name: opts:
|
name: opts:
|
||||||
if !isOption opts then
|
if !lib.isOption opts then
|
||||||
wrapModule (path ++ [ name ]) (recurse (path ++ [ name ]) opts) false
|
wrapModule (path ++ [ name ]) (recurse (path ++ [ name ]) opts) false
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
|
@ -113,7 +112,7 @@ let
|
||||||
# This is necessary to include the submodule option's definition in the docs (description, type, etc.)
|
# This is necessary to include the submodule option's definition in the docs (description, type, etc.)
|
||||||
# For instance, this helps submodules like "autoCmd" to include their base definitions and examples in the docs
|
# For instance, this helps submodules like "autoCmd" to include their base definitions and examples in the docs
|
||||||
# Though there might be a better, less "hacky" solution than this.
|
# Though there might be a better, less "hacky" solution than this.
|
||||||
${name} = recursiveUpdate opts {
|
${name} = lib.recursiveUpdate opts {
|
||||||
isOption = true;
|
isOption = true;
|
||||||
type.getSubOptions = _: _: { }; # Used to exclude suboptions from the submodule definition itself
|
type.getSubOptions = _: _: { }; # Used to exclude suboptions from the submodule definition itself
|
||||||
};
|
};
|
||||||
|
@ -122,9 +121,9 @@ let
|
||||||
else
|
else
|
||||||
wrapModule (path ++ [ name ]) opts true;
|
wrapModule (path ++ [ name ]) opts true;
|
||||||
in
|
in
|
||||||
mapAttrs g mods;
|
lib.mapAttrs g mods;
|
||||||
in
|
in
|
||||||
foldlAttrs (
|
lib.foldlAttrs (
|
||||||
acc: name: opts:
|
acc: name: opts:
|
||||||
let
|
let
|
||||||
group = if !opts.hasComponents then "Neovim Options" else "none";
|
group = if !opts.hasComponents then "Neovim Options" else "none";
|
||||||
|
@ -141,17 +140,17 @@ let
|
||||||
hasComponents = false;
|
hasComponents = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
isOpt = !opts.hasComponents && (isOption opts.index.options);
|
isOpt = !opts.hasComponents && (lib.isOption opts.index.options);
|
||||||
in
|
in
|
||||||
acc
|
acc
|
||||||
// {
|
// {
|
||||||
${group} = recursiveUpdate last {
|
${group} = lib.recursiveUpdate last {
|
||||||
index.options = optionalAttrs isOpt { ${name} = opts.index.options; };
|
index.options = lib.optionalAttrs isOpt { ${name} = opts.index.options; };
|
||||||
|
|
||||||
components = optionalAttrs (!isOpt) {
|
components = lib.optionalAttrs (!isOpt) {
|
||||||
${name} = recursiveUpdate opts {
|
${name} = lib.recursiveUpdate opts {
|
||||||
index.path = removeWhitespace (
|
index.path = removeWhitespace (
|
||||||
concatStringsSep "/" ((optional (group != "none") group) ++ [ opts.index.path ])
|
lib.concatStringsSep "/" ((lib.optional (group != "none") group) ++ [ opts.index.path ])
|
||||||
);
|
);
|
||||||
hasComponents = true;
|
hasComponents = true;
|
||||||
};
|
};
|
||||||
|
@ -177,7 +176,7 @@ let
|
||||||
else
|
else
|
||||||
f name opts;
|
f name opts;
|
||||||
in
|
in
|
||||||
concatStringsSep "\n" (mapAttrsToList g mods);
|
lib.concatStringsSep "\n" (lib.mapAttrsToList g mods);
|
||||||
in
|
in
|
||||||
recurse modules;
|
recurse modules;
|
||||||
|
|
||||||
|
@ -186,10 +185,10 @@ let
|
||||||
commands = mapModulesToString (
|
commands = mapModulesToString (
|
||||||
name: opts:
|
name: opts:
|
||||||
let
|
let
|
||||||
isBranch = if (hasSuffix "index" opts.index.path) then true else opts.hasComponents;
|
isBranch = if (lib.hasSuffix "index" opts.index.path) then true else opts.hasComponents;
|
||||||
path = if isBranch then "${opts.index.path}/index.md" else "${opts.index.path}.md";
|
path = if isBranch then "${opts.index.path}/index.md" else "${opts.index.path}.md";
|
||||||
in
|
in
|
||||||
(optionalString isBranch "mkdir -p ${opts.index.path}\n")
|
(lib.optionalString isBranch "mkdir -p ${opts.index.path}\n")
|
||||||
+ (
|
+ (
|
||||||
if opts.index.moduleDoc == null then
|
if opts.index.moduleDoc == null then
|
||||||
"cp ${mkMDDoc opts.index.options} ${path}"
|
"cp ${mkMDDoc opts.index.options} ${path}"
|
||||||
|
@ -222,7 +221,7 @@ let
|
||||||
|
|
||||||
indentLevel = with builtins; length (filter isString (split "/" opts.index.path)) - 1;
|
indentLevel = with builtins; length (filter isString (split "/" opts.index.path)) - 1;
|
||||||
|
|
||||||
padding = concatStrings (builtins.genList (_: "\t") indentLevel);
|
padding = lib.concatStrings (builtins.genList (_: "\t") indentLevel);
|
||||||
in
|
in
|
||||||
"${padding}- [${name}](${path})"
|
"${padding}- [${name}](${path})"
|
||||||
) docs.modules;
|
) docs.modules;
|
||||||
|
@ -254,7 +253,7 @@ pkgs.stdenv.mkDerivation {
|
||||||
phases = [ "buildPhase" ];
|
phases = [ "buildPhase" ];
|
||||||
|
|
||||||
buildInputs = [ pkgs.mdbook ];
|
buildInputs = [ pkgs.mdbook ];
|
||||||
inputs = sourceFilesBySuffices ./. [
|
inputs = lib.sourceFilesBySuffices ./. [
|
||||||
".md"
|
".md"
|
||||||
".toml"
|
".toml"
|
||||||
".js"
|
".js"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue