add favicons to every page

This commit is contained in:
tristan 2024-01-01 08:10:32 +00:00
parent 30ffa6c9b3
commit d723140f84
6 changed files with 129 additions and 32 deletions

View file

@ -69,6 +69,18 @@ in with html; [
actual = (para "").attrs.style;
}))
(it "needs no args to make string" (let p = tag "p";
in {
actual = toString p;
expected = "<p ></p>";
}))
(it "needs no content to make string" (let p = tag "p";
in {
actual = toString (p { class = "foobar"; });
expected = ''<p class="foobar"></p>'';
}))
(it "works recursively" (let
attrs = { style = { foo = "bar"; }; };
para = (tag "p" attrs);

View file

@ -1,15 +1,24 @@
msg:
{ actual, expected, asString ? false, asJSON ? false, removeDunders ? false, }:
if (if asString then
toString actual == toString expected
else if asJSON then
builtins.toJSON actual == builtins.toJSON expected
else if removeDunders then
builtins.removeAttrs actual [ "__toString" "__functor" ] == expected
else
actual == expected) then ''
let
preProcess = v:
if removeDunders then
builtins.removeAttrs v [ "__toString" "__functor" ]
else if asString then
toString v
else if asJSON then
builtins.toJSON v
else v;
a = preProcess actual;
e = preProcess expected;
in
if (a == e) then ''
echo 'it ${msg}'
'' else ''
''
else
''
echo 'FAILED: ${msg}'
echo '${builtins.toJSON expected}'
echo '${builtins.toJSON actual}'

View file

@ -2,6 +2,7 @@ let
html = import ../nixite/html.nix;
elems = import ../nixite/elems.nix;
site = import ../nixite/site.nix;
style = import ../nixite/style.nix;
it = import ./it.nix;
in with site; [
(it "applies a style" {
@ -42,6 +43,64 @@ in with site; [
};
asJSON = true;
})
(it "applies a favicon" {
expected = {
"index.html" = elems.html { } [
(elems.head { } [
(elems.title { } "foobar")
(elems.link {
rel = "shortcut icon";
href = ./src/favicon.png;
})
])
(elems.main { } "something")
];
blog = {
"index.html" = elems.html { } [
(elems.head { } [
(elems.title { } "foobar")
(elems.link {
rel = "shortcut icon";
href = ./src/favicon.png;
})
])
(elems.main { } "something")
];
};
};
actual = applyFavicon ./src/favicon.png {
"index.html" = elems.html { } [
(elems.head { } [ (elems.title { } "foobar") ])
(elems.main { } "something")
];
blog = {
"index.html" = elems.html { } [
(elems.head { } [ (elems.title { } "foobar") ])
(elems.main { } "something")
];
};
};
asJSON = true;
})
(it "extracts all styles" {
expected = {
"p.class" = {color = "blue";};
"a.class2" = {color = "green";};
};
actual = getStyles (let
p = style.tag "p" "class" {style = {color = "blue";};};
g = style.tag "a" "class2" {style = {color = "green";};};
in {
"index.html" = p "";
blog = {
"index.html" = g "";
};
});
removeDunders = true;
})
(it "extracts top level paths" {
actual = getPaths {
something = "";