recursive markdown rendering
This commit is contained in:
parent
5e8bb998db
commit
234c629e66
6 changed files with 90 additions and 15 deletions
|
@ -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 =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue