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-02 10:53:45 +00:00
|
|
|
in
|
2024-01-03 07:52:35 +00:00
|
|
|
with site;
|
|
|
|
describe "applyStyle" [
|
|
|
|
(it "applies a style" {
|
|
|
|
expected = {
|
2024-01-02 10:53:45 +00:00
|
|
|
"index.html" = html.tag "html" {} [
|
|
|
|
(html.tag "head" {} [
|
|
|
|
(elems.title {} "foobar")
|
|
|
|
(elems.Stylesheet "/style.css")
|
|
|
|
])
|
|
|
|
(elems.main {} "something")
|
|
|
|
];
|
|
|
|
blog = {
|
|
|
|
"index.html" = html.tag "html" {} [
|
2024-01-03 07:52:35 +00:00
|
|
|
(html.tag "head" {} [
|
|
|
|
(elems.title {} "foobar")
|
|
|
|
(elems.Stylesheet "/style.css")
|
|
|
|
])
|
2024-01-02 10:53:45 +00:00
|
|
|
(elems.main {} "blogy blog")
|
|
|
|
];
|
|
|
|
};
|
2024-01-03 07:52:35 +00:00
|
|
|
"style.css" = ''
|
|
|
|
this is a stylesheet
|
|
|
|
'';
|
2024-01-02 10:53:45 +00:00
|
|
|
};
|
2024-01-03 07:52:35 +00:00
|
|
|
actual =
|
|
|
|
applyStyle ''
|
|
|
|
this is a stylesheet
|
|
|
|
'' {
|
|
|
|
"index.html" = html.tag "html" {} [
|
|
|
|
(html.tag "head" {} [(elems.title {} "foobar")])
|
|
|
|
(elems.main {} "something")
|
|
|
|
];
|
|
|
|
blog = {
|
|
|
|
"index.html" = html.tag "html" {} [
|
|
|
|
(html.tag "head" {} [(elems.title {} "foobar")])
|
|
|
|
(elems.main {} "blogy blog")
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
asJSON = true;
|
|
|
|
})
|
|
|
|
]
|
|
|
|
++ describe "applyFavicon" [
|
|
|
|
(it "applies a favicon" {
|
|
|
|
expected = {
|
2024-01-02 10:53:45 +00:00
|
|
|
"index.html" = elems.html {} [
|
|
|
|
(elems.head {} [
|
|
|
|
(elems.title {} "foobar")
|
|
|
|
(elems.link {
|
|
|
|
rel = "shortcut icon";
|
|
|
|
href = ./src/favicon.png;
|
|
|
|
})
|
|
|
|
])
|
|
|
|
(elems.main {} "something")
|
|
|
|
];
|
2024-01-03 07:52:35 +00:00
|
|
|
blog = {
|
|
|
|
"index.html" = elems.html {} [
|
|
|
|
(elems.head {} [
|
|
|
|
(elems.title {} "foobar")
|
|
|
|
(elems.link {
|
|
|
|
rel = "shortcut icon";
|
|
|
|
href = ./src/favicon.png;
|
|
|
|
})
|
|
|
|
])
|
|
|
|
(elems.main {} "something")
|
|
|
|
];
|
|
|
|
};
|
2024-01-02 10:53:45 +00:00
|
|
|
};
|
2024-01-03 07:52:35 +00:00
|
|
|
actual = applyFavicon ./src/favicon.png {
|
2024-01-02 10:53:45 +00:00
|
|
|
"index.html" = elems.html {} [
|
|
|
|
(elems.head {} [(elems.title {} "foobar")])
|
|
|
|
(elems.main {} "something")
|
|
|
|
];
|
2024-01-03 07:52:35 +00:00
|
|
|
blog = {
|
|
|
|
"index.html" = elems.html {} [
|
|
|
|
(elems.head {} [(elems.title {} "foobar")])
|
|
|
|
(elems.main {} "something")
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
asJSON = true;
|
|
|
|
})
|
|
|
|
]
|
|
|
|
++ describe "getStyles" [
|
|
|
|
(it "gets all styles" {
|
|
|
|
expected = {
|
|
|
|
"p" = {};
|
|
|
|
"div" = {};
|
|
|
|
"p.class" = {color = "blue";};
|
|
|
|
"div.class2" = {color = "green";};
|
|
|
|
};
|
|
|
|
actual = 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;
|
|
|
|
})
|
|
|
|
]
|
|
|
|
++ 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;} "")]
|
|
|
|
];
|
|
|
|
};
|
|
|
|
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" [
|
|
|
|
(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";}];
|
|
|
|
};
|
|
|
|
}))
|
|
|
|
]
|
|
|
|
++ describe "getLinks" [
|
|
|
|
(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
|
|
|
}))
|
|
|
|
]
|
|
|
|
++ describe "extractLinks" [
|
|
|
|
(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";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}))
|
|
|
|
]
|
|
|
|
++ describe "copyTo" [
|
|
|
|
(it "copies all the files" {
|
|
|
|
actual = copyTo "." {
|
|
|
|
page = "this is a page";
|
|
|
|
subdir = {
|
|
|
|
page = "this page is in a subdir";
|
|
|
|
link = ./src;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
expected = ''
|
|
|
|
cp /nix/store/crirfz0n6f8dgl1si3x7pwyw7fqm0r8l-page ./page
|
|
|
|
mkdir -p ./subdir
|
|
|
|
cp -r /nix/store/q95cn7ccixzi9w22aic4bl0ykk40ka7v-src ./subdir/link
|
|
|
|
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page
|
2024-01-01 09:57:58 +00:00
|
|
|
|
2024-01-03 07:52:35 +00:00
|
|
|
'';
|
|
|
|
})
|
2024-01-01 13:48:26 +00:00
|
|
|
|
2024-01-03 07:52:35 +00:00
|
|
|
(it "throws with a list for a page" {
|
|
|
|
actual = copyTo "." {page = [];};
|
|
|
|
throws = true;
|
|
|
|
})
|
2024-01-01 13:48:26 +00:00
|
|
|
|
2024-01-03 07:52:35 +00:00
|
|
|
(it "throws with null for a page" {
|
|
|
|
actual = copyTo "." {page = null;};
|
|
|
|
throws = true;
|
|
|
|
})
|
2024-01-01 13:48:26 +00:00
|
|
|
|
2024-01-03 07:52:35 +00:00
|
|
|
(it "throws with a bool for a page" {
|
|
|
|
actual = copyTo "." {page = true;};
|
|
|
|
throws = true;
|
|
|
|
})
|
2024-01-01 13:48:26 +00:00
|
|
|
|
2024-01-03 07:52:35 +00:00
|
|
|
(it "throws with a number for a page" {
|
|
|
|
actual = copyTo "." {page = 5;};
|
|
|
|
throws = true;
|
|
|
|
})
|
|
|
|
]
|
|
|
|
++ describe "prepare" [
|
|
|
|
(it "prepares the site" {
|
|
|
|
actual = prepare {favicon = ./src/favicon.png;} {
|
2024-01-02 10:53:45 +00:00
|
|
|
"index.html" = elems.html {} [
|
|
|
|
(elems.head {} [(elems.title {} "foobar")])
|
2024-01-03 07:52:35 +00:00
|
|
|
(elems.main {} [
|
|
|
|
(elems.a {
|
|
|
|
href = {
|
|
|
|
type = "link";
|
|
|
|
name = "a-page";
|
|
|
|
content = "this is another page";
|
|
|
|
};
|
|
|
|
} "A Page")
|
|
|
|
])
|
2024-01-02 10:53:45 +00:00
|
|
|
];
|
2024-01-03 07:52:35 +00:00
|
|
|
blog = {
|
|
|
|
"index.html" = elems.html {} [
|
|
|
|
(elems.head {} [(elems.title {} "foobar")])
|
|
|
|
(elems.main {} "something")
|
|
|
|
];
|
|
|
|
};
|
2024-01-02 10:53:45 +00:00
|
|
|
};
|
2024-01-03 07:52:35 +00:00
|
|
|
expected = {
|
2024-01-02 10:53:45 +00:00
|
|
|
"index.html" = elems.html {} [
|
|
|
|
(elems.head {} [
|
|
|
|
(elems.title {} "foobar")
|
|
|
|
(elems.link {
|
|
|
|
rel = "shortcut icon";
|
|
|
|
href = "/static/favicon.png";
|
|
|
|
})
|
|
|
|
(elems.Stylesheet "/style.css")
|
|
|
|
])
|
2024-01-03 07:52:35 +00:00
|
|
|
(elems.main {} [(elems.a {href = "/static/a-page";} "A Page")])
|
2024-01-02 10:53:45 +00:00
|
|
|
];
|
2024-01-03 07:52:35 +00:00
|
|
|
blog = {
|
|
|
|
"index.html" = elems.html {} [
|
|
|
|
(elems.head {} [
|
|
|
|
(elems.title {} "foobar")
|
|
|
|
(elems.link {
|
|
|
|
rel = "shortcut icon";
|
|
|
|
href = "/static/favicon.png";
|
|
|
|
})
|
|
|
|
(elems.Stylesheet "/style.css")
|
|
|
|
])
|
|
|
|
(elems.main {} "something")
|
|
|
|
];
|
|
|
|
};
|
|
|
|
static = {
|
|
|
|
"favicon.png" = ./src/favicon.png;
|
|
|
|
"a-page" = "this is another page";
|
|
|
|
};
|
|
|
|
"style.css" = "";
|
2024-01-02 10:53:45 +00:00
|
|
|
};
|
2024-01-03 07:52:35 +00:00
|
|
|
asJSON = true;
|
|
|
|
})
|
|
|
|
]
|