extract direct paths
This commit is contained in:
parent
77f70490df
commit
c36fece776
|
@ -20,14 +20,16 @@
|
|||
style = nixite.style;
|
||||
|
||||
packages.${system} = {
|
||||
default = nixite.mkSite (nixite.site.applyStyle ./testing/src/style.css {
|
||||
default = nixite.mkSite (
|
||||
nixite.site.applyStyle ./testing/src/style.css
|
||||
(nixite.site.extractPaths {
|
||||
"index.html" = with nixite.elems; (doc [
|
||||
[
|
||||
(title "Nixite")
|
||||
]
|
||||
(main [
|
||||
(nixite.md.readMd ./testing/src/index.md)
|
||||
(link "/blog" "blog")
|
||||
(nixite.html.tag "img" {src = ./testing/src/favicon.png;} "")
|
||||
(list [
|
||||
"item 1"
|
||||
"item 2"
|
||||
|
@ -48,7 +50,7 @@
|
|||
])
|
||||
]);
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
serve = self.serve self.packages.${system}.default;
|
||||
|
||||
|
|
|
@ -14,6 +14,38 @@ in rec {
|
|||
)
|
||||
site);
|
||||
|
||||
extractPaths = content:
|
||||
switchPaths content // {static = getPaths content;};
|
||||
|
||||
switchPaths = content: (
|
||||
if builtins.isAttrs content
|
||||
then
|
||||
builtins.mapAttrs (key: value:
|
||||
if builtins.isPath value
|
||||
then ("/static/" + baseNameOf value)
|
||||
else switchPaths value)
|
||||
content
|
||||
else if builtins.isList content
|
||||
then (map switchPaths content)
|
||||
else content
|
||||
);
|
||||
|
||||
getPaths = content: (builtins.listToAttrs (getPathsKV content));
|
||||
|
||||
getPathsKV = path:
|
||||
(if builtins.isPath path
|
||||
then [
|
||||
{
|
||||
name = baseNameOf path;
|
||||
value = path;
|
||||
}
|
||||
]
|
||||
else if builtins.isAttrs path
|
||||
then builtins.concatLists (map getPathsKV ( builtins.attrValues path ))
|
||||
else if builtins.isList path
|
||||
then builtins.concatLists (map getPathsKV path)
|
||||
else []);
|
||||
|
||||
copyTo = prefix: site:
|
||||
builtins.toString (
|
||||
builtins.attrValues (
|
||||
|
|
|
@ -37,4 +37,71 @@ in
|
|||
};
|
||||
};
|
||||
})
|
||||
(it "extracts top level paths" {
|
||||
actual = getPaths {
|
||||
something = "";
|
||||
src = ./src/index.md;
|
||||
};
|
||||
expected = {
|
||||
"index.md" = ./src/index.md;
|
||||
};
|
||||
})
|
||||
(it "extracts lower level paths" {
|
||||
actual = getPaths {
|
||||
something = "yes";
|
||||
a-list = [
|
||||
{thingy = ./src/index.md;}
|
||||
[(html.tag "img" {src = ./src/favicon.png;} "")]
|
||||
];
|
||||
};
|
||||
expected = {
|
||||
"index.md" = ./src/index.md;
|
||||
"favicon.png" = ./src/favicon.png;
|
||||
};
|
||||
})
|
||||
(it "switches paths" {
|
||||
actual = switchPaths {
|
||||
something = "";
|
||||
a-thing = {
|
||||
src = ./src/index.md;
|
||||
};
|
||||
a-list = [
|
||||
{thingy = ./src/index.md;}
|
||||
];
|
||||
};
|
||||
expected = {
|
||||
something = "";
|
||||
a-thing = {
|
||||
src = "/static/index.md";
|
||||
};
|
||||
a-list = [
|
||||
{thingy = "/static/index.md";}
|
||||
];
|
||||
};
|
||||
})
|
||||
|
||||
(it "extracts paths" {
|
||||
actual = extractPaths {
|
||||
something = "";
|
||||
a-thing = {
|
||||
src = ./src/index.md;
|
||||
};
|
||||
a-list = [
|
||||
{thingy = ./src/index.md;}
|
||||
];
|
||||
};
|
||||
expected = {
|
||||
something = "";
|
||||
a-thing = {
|
||||
src = "/static/index.md";
|
||||
};
|
||||
a-list = [
|
||||
{thingy = "/static/index.md";}
|
||||
];
|
||||
static = {
|
||||
"index.md" = ./src/index.md;
|
||||
};
|
||||
};
|
||||
})
|
||||
|
||||
]
|
||||
|
|
BIN
testing/src/favicon.png
Normal file
BIN
testing/src/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in a new issue