1
0
forked from clan/clan-core

Add toml frontmatter description to jsonschema

This commit is contained in:
Johannes Kirschbauer 2024-06-26 15:10:21 +02:00
parent cecd6011d6
commit 3777a4cf02
Signed by: hsjobeki
SSH Key Fingerprint: SHA256:vX3utDqig7Ph5L0JPv87ZTPb/w7cMzREKVZzzLFg9qU
3 changed files with 33 additions and 34 deletions

View File

@ -8,7 +8,6 @@
evalClanModules = import ./eval-clan-modules { inherit clan-core nixpkgs lib; };
inventory = import ./inventory { inherit lib clan-core; };
jsonschema = import ./jsonschema { inherit lib; };
# TODO: migrate to also use toml frontmatter
# modules = import ./description.nix { inherit clan-core lib; };
modules = import ./description.nix { inherit clan-core lib; };
buildClan = import ./build-clan { inherit clan-core lib nixpkgs; };
}

View File

@ -1,33 +1,34 @@
{ ... }:
{ clan-core, lib }:
rec {
# getReadme =
# modulename:
# let
# readme = "${clan-core}/clanModules/${modulename}/README.md";
# readmeContents =
# if (builtins.pathExists readme) then
# (builtins.readFile readme)
# else
# throw "No README.md found for module ${modulename}";
# in
# readmeContents;
getReadme =
modulename:
let
readme = "${clan-core}/clanModules/${modulename}/README.md";
readmeContents =
if (builtins.pathExists readme) then
(builtins.readFile readme)
else
throw "No README.md found for module ${modulename}";
in
readmeContents;
# getShortDescription =
# modulename:
# let
# content = (getReadme modulename);
# parts = lib.splitString "---" content;
# description = builtins.head parts;
# number_of_newlines = builtins.length (lib.splitString "\n" description);
# in
# if (builtins.length parts) > 1 then
# if number_of_newlines > 4 then
# throw "Short description in README.md for module ${modulename} is too long. Max 3 newlines."
# else if number_of_newlines <= 1 then
# throw "Missing short description in README.md for module ${modulename}."
# else
# description
# else
# throw "Short description delimiter `---` not found in README.md for module ${modulename}";
getShortDescription =
modulename:
let
content = getReadme modulename;
parts = lib.splitString "---" content;
# Partition the parts into the first part (the readme content) and the rest (the metadata)
parsed = builtins.partition ({ index }: if index >= 2 then false else true) (
lib.filter ({ index, ... }: index != 0) (lib.imap0 (index: part: { inherit index part; }) parts)
);
# Use this if the content is needed
# readmeContent = lib.concatMapStrings (v: "---" + v.part) parsed.wrong;
meta = builtins.fromTOML (builtins.head parsed.right).part;
in
if (builtins.length parts >= 3) then
meta.description
else
throw "Short description delimiter `---` not found in README.md for module ${modulename}";
}

View File

@ -23,8 +23,7 @@
clanModuleFunctionSchemas = lib.mapAttrsFlatten (modulename: _: {
name = modulename;
# TODO: migrate to new toml format
# description = self.lib.modules.getShortDescription modulename;
description = self.lib.modules.getShortDescription modulename;
parameters = self.lib.jsonschema.parseOptions (optionsFromModule modulename);
}) clanModules;
in