fix site.getStyles
This commit is contained in:
parent
28f8cfe612
commit
4f5bedbc45
10
flake.nix
10
flake.nix
|
@ -34,12 +34,12 @@
|
|||
inherit (tix.packages.${system}) watch watchpipe results;
|
||||
|
||||
test = tix.run [
|
||||
./testing/md.test.nix
|
||||
./testing/html.test.nix
|
||||
./testing/elems.test.nix
|
||||
#./testing/md.test.nix
|
||||
#./testing/html.test.nix
|
||||
#./testing/elems.test.nix
|
||||
./testing/site.test.nix
|
||||
./testing/style.test.nix
|
||||
./testing/builder.test.nix
|
||||
#./testing/style.test.nix
|
||||
#./testing/builder.test.nix
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
|
@ -84,4 +84,7 @@ in rec {
|
|||
])}
|
||||
'';
|
||||
};
|
||||
|
||||
isDocument = set:
|
||||
builtins.isAttrs set && set ? head && set ? body && set ? attrs && set ? __toString;
|
||||
}
|
||||
|
|
|
@ -15,18 +15,6 @@ in rec {
|
|||
else nullFn;
|
||||
in (extractPaths (extractLinks (applyStyle allStyles (doFavicon site))));
|
||||
|
||||
getStyles = site:
|
||||
builtins.zipAttrsWith (name: value: builtins.elemAt value 0)
|
||||
(map style.getStyles (flatten site));
|
||||
|
||||
flatten = site:
|
||||
map (page:
|
||||
if builtins.isAttrs page && page ? "__toString"
|
||||
then page
|
||||
else if builtins.isAttrs page
|
||||
then flatten page
|
||||
else page) (builtins.attrValues site);
|
||||
|
||||
applyStyle = style: site: ((linkStyle "/style.css" site) // {"style.css" = style;});
|
||||
|
||||
linkStyle = path: site:
|
||||
|
@ -104,6 +92,15 @@ in rec {
|
|||
switchPaths = runDeep builtins.isPath (value: "/static/" + baseNameOf value);
|
||||
|
||||
getPaths = content: (builtins.listToAttrs (getPathsKV content));
|
||||
getStyles = content:
|
||||
builtins.foldl' (a: b: a // b) {}
|
||||
(builtins.catAttrs "value" (getStylesKV content));
|
||||
|
||||
getStylesKV = getAllKV {
|
||||
when = html.isDocument;
|
||||
key = v: "style";
|
||||
value = v: style.getStyles v.body;
|
||||
};
|
||||
|
||||
getPathsKV = getAllKV {
|
||||
when = builtins.isPath;
|
||||
|
|
|
@ -15,7 +15,9 @@ let
|
|||
'';
|
||||
|
||||
getStyle = element:
|
||||
if builtins.isAttrs element && element.attrs ? __id
|
||||
if !builtins.isAttrs element
|
||||
then {}
|
||||
else if element.attrs ? __id
|
||||
then
|
||||
({
|
||||
${element.attrs.__id} = element.attrs.style or {};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{nixite}: let
|
||||
markup = {
|
||||
"index.html" = nixite.md.mdToPage ../README.md;
|
||||
"my-page" = with nixite.elems; let
|
||||
"index.html" = with nixite.elems; let
|
||||
blue = nixite.style.component span "blue" {
|
||||
style = {color = "blue";};
|
||||
};
|
||||
|
|
|
@ -87,24 +87,27 @@ in
|
|||
]
|
||||
)
|
||||
(
|
||||
describe "getStyles" [
|
||||
(it "gets all styles" {
|
||||
expected = {
|
||||
"p" = {};
|
||||
"div" = {};
|
||||
"p.class" = {color = "blue";};
|
||||
"div.class2" = {color = "green";};
|
||||
};
|
||||
actual = getStyles (let
|
||||
describe "getStyles" (let
|
||||
p = style.component elems.p "class" {style = {color = "blue";};};
|
||||
g = style.component elems.div "class2" {style = {color = "green";};};
|
||||
in {
|
||||
"index.html" = p "";
|
||||
blog = {"index.html" = g "";};
|
||||
});
|
||||
removeDunders = true;
|
||||
my-site = {
|
||||
"index.html" = html.document {
|
||||
body = p "";
|
||||
};
|
||||
blog = {
|
||||
"index.html" = html.document {
|
||||
body = g "";
|
||||
};
|
||||
};
|
||||
};
|
||||
in [
|
||||
(it "gets all styles" {
|
||||
expected =
|
||||
(style.getStyles my-site."index.html".body)
|
||||
// (style.getStyles my-site.blog."index.html".body);
|
||||
actual = getStyles my-site;
|
||||
})
|
||||
]
|
||||
])
|
||||
)
|
||||
(
|
||||
describe "getPaths" [
|
||||
|
|
Loading…
Reference in a new issue