recursive markdown rendering

This commit is contained in:
tristan 2023-12-31 10:33:05 +00:00
parent 5e8bb998db
commit 234c629e66
6 changed files with 90 additions and 15 deletions

View file

@ -5,11 +5,46 @@ in rec {
if builtins.isPath md
then processMd (builtins.readFile md)
else processMd md;
processMd = md: (map (c:
if builtins.isString c
then mdBlock c
else "") (builtins.split "\n\n" md));
recReadMd = root:
assert builtins.isPath root;
builtins.mapAttrs
(path: type:
if type == "directory"
then recReadMd (root + (/. + path))
else if type == "regular"
then mdToPage (root + (/. + path))
else throw "Cannot read ${path}, file type ${type}")
(builtins.readDir root);
recFixAppendix = site:
builtins.listToAttrs (
builtins.attrValues (
builtins.mapAttrs (name: value: {
name = fixAppendix name;
value =
if builtins.isAttrs value
then recFixAppendix value
else value;
})
site
)
);
fixAppendix = builtins.replaceStrings [".md"] [".html"];
readDir = root: recFixAppendix (recReadMd root);
mdToPage = md: elems.doc [
[(elems.title "markdown file")]
(readMd md)
];
mdBlock = block: let
m = heading block;
h =