2024-01-03 07:52:35 +00:00
|
|
|
{
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
...
|
|
|
|
}: let
|
2023-12-31 04:27:09 +00:00
|
|
|
html = import ../nixite/html.nix;
|
2023-12-31 00:24:48 +00:00
|
|
|
elems = import ../nixite/elems.nix;
|
|
|
|
site = import ../nixite/site.nix;
|
2024-01-01 08:10:32 +00:00
|
|
|
style = import ../nixite/style.nix;
|
2024-01-03 13:19:41 +00:00
|
|
|
my-site = {
|
|
|
|
"index.html" = html.document {
|
|
|
|
head = [(elems.title {} "foobar")];
|
|
|
|
body = [(elems.main {} "something")];
|
|
|
|
};
|
|
|
|
blog = {
|
|
|
|
"index.html" = html.document {
|
|
|
|
head = [(elems.title {} "foobar")];
|
|
|
|
body = elems.main {} "blogy blog";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-01-02 10:53:45 +00:00
|
|
|
in
|
2024-01-03 13:19:41 +00:00
|
|
|
with site; [
|
|
|
|
(
|
|
|
|
describe "linkStyle" [
|
|
|
|
(it "links a stylesheet" {
|
|
|
|
actual = linkStyle "my-styles.css" my-site;
|
|
|
|
expected = {
|
|
|
|
"index.html" = html.addToHead my-site."index.html" [(elems.Stylesheet "my-styles.css")];
|
|
|
|
blog = {
|
|
|
|
"index.html" = html.addToHead my-site.blog."index.html" [(elems.Stylesheet "my-styles.css")];
|
|
|
|
};
|
2024-01-02 10:53:45 +00:00
|
|
|
};
|
2024-01-03 13:19:41 +00:00
|
|
|
asJSON = true;
|
|
|
|
})
|
|
|
|
]
|
|
|
|
)
|
|
|
|
(
|
|
|
|
describe "applyStyle" [
|
|
|
|
(it "applies a style" {
|
|
|
|
expected = {
|
|
|
|
"index.html" = html.addToHead my-site."index.html" [(elems.Stylesheet "/style.css")];
|
2024-01-03 07:52:35 +00:00
|
|
|
blog = {
|
2024-01-03 13:19:41 +00:00
|
|
|
"index.html" = html.addToHead my-site.blog."index.html" [(elems.Stylesheet "/style.css")];
|
2024-01-03 07:52:35 +00:00
|
|
|
};
|
2024-01-03 13:19:41 +00:00
|
|
|
"style.css" = ''
|
|
|
|
this is a stylesheet
|
|
|
|
'';
|
2024-01-03 07:52:35 +00:00
|
|
|
};
|
2024-01-03 13:19:41 +00:00
|
|
|
actual =
|
|
|
|
applyStyle ''
|
|
|
|
this is a stylesheet
|
|
|
|
''
|
|
|
|
my-site;
|
|
|
|
asJSON = true;
|
|
|
|
})
|
|
|
|
]
|
|
|
|
)
|
|
|
|
(
|
|
|
|
describe "applyFavicon" [
|
|
|
|
(it "applies a favicon" (
|
|
|
|
let
|
|
|
|
href = "my-favicon.ico";
|
|
|
|
favicon-link = elems.link {
|
|
|
|
rel = "shortcut icon";
|
|
|
|
inherit href;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
expected = {
|
|
|
|
"index.html" =
|
|
|
|
my-site."index.html"
|
|
|
|
// {
|
|
|
|
head = my-site."index.html".head ++ [favicon-link];
|
|
|
|
};
|
|
|
|
blog = {
|
|
|
|
"index.html" =
|
|
|
|
my-site.blog."index.html"
|
|
|
|
// {
|
|
|
|
head = my-site.blog."index.html".head ++ [favicon-link];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
actual =
|
|
|
|
applyFavicon href my-site;
|
|
|
|
}
|
|
|
|
))
|
|
|
|
]
|
|
|
|
)
|
|
|
|
(
|
2024-01-04 12:57:05 +00:00
|
|
|
describe "getStyles" (let
|
|
|
|
p = style.component elems.p "class" {style = {color = "blue";};};
|
|
|
|
g = style.component elems.div "class2" {style = {color = "green";};};
|
|
|
|
my-site = {
|
|
|
|
"index.html" = html.document {
|
|
|
|
body = p "";
|
2024-01-03 07:52:35 +00:00
|
|
|
};
|
2024-01-04 12:57:05 +00:00
|
|
|
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;
|
2024-01-03 13:19:41 +00:00
|
|
|
})
|
2024-01-04 12:57:05 +00:00
|
|
|
])
|
2024-01-03 13:19:41 +00:00
|
|
|
)
|
|
|
|
(
|
|
|
|
describe "getPaths" [
|
|
|
|
(it "gets top level paths" {
|
|
|
|
actual = getPaths {
|
|
|
|
something = "";
|
|
|
|
src = ./src/index.md;
|
|
|
|
};
|
|
|
|
expected = {"index.md" = ./src/index.md;};
|
|
|
|
})
|
|
|
|
(it "gets lower level paths" {
|
|
|
|
actual = getPaths {
|
|
|
|
something = "yes";
|
|
|
|
a-list = [
|
|
|
|
{thingy = ./src/index.md;}
|
|
|
|
[(html.tag "img" {src = ./src/favicon.png;} "")]
|
2024-01-03 07:52:35 +00:00
|
|
|
];
|
|
|
|
};
|
2024-01-03 13:19:41 +00:00
|
|
|
expected = {
|
|
|
|
"index.md" = ./src/index.md;
|
|
|
|
"favicon.png" = ./src/favicon.png;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]
|
|
|
|
)
|
|
|
|
(
|
|
|
|
describe "switchPaths" [
|
|
|
|
(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";}];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]
|
|
|
|
)
|
|
|
|
(
|
|
|
|
describe "extractPaths" [
|
|
|
|
(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;};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]
|
|
|
|
)
|
|
|
|
(describe "switchLinks" [
|
2024-01-03 07:52:35 +00:00
|
|
|
(it "switches links" (let
|
|
|
|
coolPage = {
|
|
|
|
type = "link";
|
|
|
|
name = "cool-page";
|
|
|
|
content = "";
|
2024-01-02 10:53:45 +00:00
|
|
|
};
|
|
|
|
in {
|
2024-01-03 07:52:35 +00:00
|
|
|
actual = switchLinks {
|
|
|
|
something = "";
|
|
|
|
a-thing = {src = coolPage;};
|
|
|
|
a-list = [{thingy = coolPage;}];
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
something = "";
|
|
|
|
a-thing = {src = "/static/cool-page";};
|
|
|
|
a-list = [{thingy = "/static/cool-page";}];
|
|
|
|
};
|
|
|
|
}))
|
2024-01-03 13:19:41 +00:00
|
|
|
])
|
|
|
|
(describe "getLinks" [
|
2024-01-03 07:52:35 +00:00
|
|
|
(it "gets links" (let
|
|
|
|
coolPage = {
|
|
|
|
type = "link";
|
|
|
|
name = "cool-page";
|
|
|
|
content = "cool content";
|
|
|
|
};
|
|
|
|
otherPage = {
|
|
|
|
type = "link";
|
|
|
|
name = "page2";
|
|
|
|
content = "stuff";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
actual = getLinks {
|
|
|
|
something = "yes";
|
|
|
|
a-list = [{thingy = coolPage;} [(elems.img {src = otherPage;} "")]];
|
|
|
|
};
|
|
|
|
expected = {
|
2024-01-02 10:53:45 +00:00
|
|
|
"cool-page" = "cool content";
|
|
|
|
"page2" = "stuff";
|
|
|
|
};
|
2024-01-03 07:52:35 +00:00
|
|
|
}))
|
2024-01-03 13:19:41 +00:00
|
|
|
])
|
|
|
|
(describe "extractLinks" [
|
2024-01-03 07:52:35 +00:00
|
|
|
(it "extracts links" (let
|
|
|
|
coolPage = {
|
|
|
|
type = "link";
|
|
|
|
name = "cool-page";
|
|
|
|
content = "cool content";
|
2024-01-02 10:53:45 +00:00
|
|
|
};
|
2024-01-03 07:52:35 +00:00
|
|
|
otherPage = {
|
|
|
|
type = "link";
|
|
|
|
name = "page2";
|
|
|
|
content = "stuff";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
actual = extractLinks {
|
|
|
|
something = "";
|
|
|
|
a-thing = {src = coolPage;};
|
|
|
|
a-list = [{thingy = otherPage;}];
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
something = "";
|
|
|
|
a-thing = {src = "/static/cool-page";};
|
|
|
|
a-list = [{thingy = "/static/page2";}];
|
|
|
|
static = {
|
|
|
|
"cool-page" = "cool content";
|
|
|
|
"page2" = "stuff";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}))
|
2024-01-03 13:19:41 +00:00
|
|
|
])
|
|
|
|
(describe "prepare" [
|
2024-01-03 07:52:35 +00:00
|
|
|
(it "prepares the site" {
|
2024-01-03 13:19:41 +00:00
|
|
|
actual = prepare {favicon = ./src/favicon.png;} my-site;
|
|
|
|
expected = let
|
|
|
|
my-favicon-link = elems.link {
|
|
|
|
rel = "shortcut icon";
|
|
|
|
href = "/static/favicon.png";
|
|
|
|
};
|
|
|
|
my-style = elems.Stylesheet "/style.css";
|
|
|
|
in {
|
|
|
|
"index.html" = html.document {
|
|
|
|
head =
|
|
|
|
my-site."index.html".head
|
|
|
|
++ [my-favicon-link my-style];
|
|
|
|
body = my-site."index.html".body;
|
2024-01-03 07:52:35 +00:00
|
|
|
};
|
|
|
|
blog = {
|
2024-01-03 13:19:41 +00:00
|
|
|
"index.html" = html.document {
|
|
|
|
body = my-site.blog."index.html".body;
|
|
|
|
head =
|
|
|
|
my-site.blog."index.html".head
|
|
|
|
++ [my-favicon-link my-style];
|
|
|
|
};
|
2024-01-03 07:52:35 +00:00
|
|
|
};
|
|
|
|
static = {
|
|
|
|
"favicon.png" = ./src/favicon.png;
|
|
|
|
};
|
|
|
|
"style.css" = "";
|
2024-01-02 10:53:45 +00:00
|
|
|
};
|
2024-01-03 07:52:35 +00:00
|
|
|
asJSON = true;
|
|
|
|
})
|
2024-01-03 13:19:41 +00:00
|
|
|
])
|
|
|
|
]
|