component extending, add all html elems
also use nixfmt
This commit is contained in:
parent
ccc6b53b91
commit
cb6d9652f8
15 changed files with 548 additions and 604 deletions
|
@ -1,60 +1,42 @@
|
|||
let
|
||||
elems = import ./elems.nix;
|
||||
let elems = import ./elems.nix;
|
||||
in rec {
|
||||
readMd = md:
|
||||
if builtins.isPath md
|
||||
then processMd (builtins.readFile md)
|
||||
else processMd md;
|
||||
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));
|
||||
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);
|
||||
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
|
||||
)
|
||||
);
|
||||
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"];
|
||||
fixAppendix = builtins.replaceStrings [ ".md" ] [ ".html" ];
|
||||
|
||||
readDir = root: recFixAppendix (recReadMd root);
|
||||
|
||||
mdToPage = md: elems.doc [
|
||||
[(elems.title "markdown file")]
|
||||
(readMd md)
|
||||
];
|
||||
mdToPage = md: elems.Doc [ [ (elems.title "markdown file") ] (readMd md) ];
|
||||
|
||||
mdBlock = block: let
|
||||
m = heading block;
|
||||
h =
|
||||
if m == null
|
||||
then 0
|
||||
else builtins.stringLength (builtins.elemAt m 0);
|
||||
in
|
||||
if m == null
|
||||
then elems.p {} block
|
||||
else elems.h h (builtins.elemAt m 1);
|
||||
mdBlock = block:
|
||||
let
|
||||
m = heading block;
|
||||
h = if m == null then 0 else builtins.stringLength (builtins.elemAt m 0);
|
||||
in if m == null then elems.p { } block else elems.H h (builtins.elemAt m 1);
|
||||
|
||||
heading = block: builtins.match "(#+) (.*)" block;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue