alejandra
This commit is contained in:
parent
b1426fb1ca
commit
dc33fdf093
|
@ -37,11 +37,11 @@
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1704187012,
|
"lastModified": 1704192724,
|
||||||
"narHash": "sha256-td0PQa1cTvjurjBmLpCynAgDV425Mh8sRObRtbTGxiQ=",
|
"narHash": "sha256-Cx9os5FQU4UTjxt/uE1trPHxegXyhvV/wSiIiBWTDt0=",
|
||||||
"ref": "refs/heads/master",
|
"ref": "refs/heads/master",
|
||||||
"rev": "249bd9cda4fe9b02f3c85b22179109794eb57256",
|
"rev": "b800bb46955d69cf7693d7c788a4d624eff2717f",
|
||||||
"revCount": 2,
|
"revCount": 3,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.tristans.cloud/tristan/tix"
|
"url": "https://git.tristans.cloud/tristan/tix"
|
||||||
},
|
},
|
||||||
|
|
24
flake.nix
24
flake.nix
|
@ -3,12 +3,17 @@
|
||||||
|
|
||||||
inputs = {tix.url = "git+https://git.tristans.cloud/tristan/tix";};
|
inputs = {tix.url = "git+https://git.tristans.cloud/tristan/tix";};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, tix }:
|
outputs = {
|
||||||
let
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
tix,
|
||||||
|
}: let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = import nixpkgs {inherit system;};
|
pkgs = import nixpkgs {inherit system;};
|
||||||
nixite = import ./nixite/. {inherit pkgs;};
|
nixite = import ./nixite/. {inherit pkgs;};
|
||||||
in nixite // {
|
in
|
||||||
|
nixite
|
||||||
|
// {
|
||||||
packages.${system} = {
|
packages.${system} = {
|
||||||
raw = nixite.mkSite (let
|
raw = nixite.mkSite (let
|
||||||
readme = {
|
readme = {
|
||||||
|
@ -16,8 +21,7 @@
|
||||||
content = nixite.md.mdToPage ./README.md;
|
content = nixite.md.mdToPage ./README.md;
|
||||||
};
|
};
|
||||||
markup = {
|
markup = {
|
||||||
"index.html" = with nixite.elems;
|
"index.html" = with nixite.elems; let
|
||||||
let
|
|
||||||
blue = nixite.style.component span "blue" {
|
blue = nixite.style.component span "blue" {
|
||||||
style = {color = "blue";};
|
style = {color = "blue";};
|
||||||
};
|
};
|
||||||
|
@ -40,9 +44,11 @@
|
||||||
]);
|
]);
|
||||||
blog = nixite.md.readDir ./testing/blog;
|
blog = nixite.md.readDir ./testing/blog;
|
||||||
};
|
};
|
||||||
site = (nixite.site.prepare { favicon = ./testing/src/favicon.png; }
|
site =
|
||||||
markup);
|
nixite.site.prepare {favicon = ./testing/src/favicon.png;}
|
||||||
in site);
|
markup;
|
||||||
|
in
|
||||||
|
site);
|
||||||
|
|
||||||
default = nixite.serve self.packages.${system}.raw;
|
default = nixite.serve self.packages.${system}.raw;
|
||||||
|
|
||||||
|
@ -54,7 +60,7 @@
|
||||||
./testing/style.test.nix
|
./testing/style.test.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
watch = tix.watch "nix run .#test --show-trace" "fx";
|
watch = tix.watch "nix run .#test | ${pkgs.fx}/bin/fx" "fx";
|
||||||
|
|
||||||
dev = tix.watch "nix run .# --show-trace" "caddy";
|
dev = tix.watch "nix run .# --show-trace" "caddy";
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{pkgs, ...}: {
|
{pkgs, ...}: {
|
||||||
mkSite = import ./make-site.nix pkgs;
|
mkSite = import ./make-site.nix pkgs;
|
||||||
serve = site:
|
serve = site: (pkgs.writeShellScriptBin "serve" ''
|
||||||
(pkgs.writeShellScriptBin "serve" ''
|
|
||||||
${pkgs.caddy}/bin/caddy file-server --root ${site}
|
${pkgs.caddy}/bin/caddy file-server --root ${site}
|
||||||
'');
|
'');
|
||||||
md = import ./md.nix;
|
md = import ./md.nix;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
let html = import ./html.nix;
|
let
|
||||||
|
html = import ./html.nix;
|
||||||
in {
|
in {
|
||||||
html = html.tag "html";
|
html = html.tag "html";
|
||||||
# Document metadata
|
# Document metadata
|
||||||
|
@ -41,12 +42,14 @@ in {
|
||||||
main = html.tag "main";
|
main = html.tag "main";
|
||||||
div = html.tag "div";
|
div = html.tag "div";
|
||||||
# Text-level semantics
|
# Text-level semantics
|
||||||
a = html.tag "a" // {
|
a =
|
||||||
__functor = self: href:
|
html.tag "a"
|
||||||
(if builtins.isString href then
|
// {
|
||||||
(self // html.baseTag) { inherit href; }
|
__functor = self: href: (
|
||||||
else
|
if builtins.isString href
|
||||||
(self // html.baseTag) href);
|
then (self // html.baseTag) {inherit href;}
|
||||||
|
else (self // html.baseTag) href
|
||||||
|
);
|
||||||
};
|
};
|
||||||
em = html.tag "em";
|
em = html.tag "em";
|
||||||
strong = html.tag "strong";
|
strong = html.tag "strong";
|
||||||
|
@ -130,12 +133,14 @@ in {
|
||||||
canvas = html.tag "canvas";
|
canvas = html.tag "canvas";
|
||||||
|
|
||||||
# custom
|
# custom
|
||||||
List = html.tag "ul" // {
|
List =
|
||||||
__functor = self: children:
|
html.tag "ul"
|
||||||
(if builtins.isList children then
|
// {
|
||||||
(self // html.baseTag) (map (html.tag "li") children)
|
__functor = self: children: (
|
||||||
else
|
if builtins.isList children
|
||||||
html.incorporateAttrs self children);
|
then (self // html.baseTag) (map (html.tag "li") children)
|
||||||
|
else html.incorporateAttrs self children
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Doc = params: child:
|
Doc = params: child:
|
||||||
|
@ -149,5 +154,10 @@ in {
|
||||||
Stylesheet = params:
|
Stylesheet = params:
|
||||||
html.tag "link" ({
|
html.tag "link" ({
|
||||||
rel = "stylesheet";
|
rel = "stylesheet";
|
||||||
} // (if builtins.isString params then { href = params; } else params)) "";
|
}
|
||||||
|
// (
|
||||||
|
if builtins.isString params
|
||||||
|
then {href = params;}
|
||||||
|
else params
|
||||||
|
)) "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,70 +1,78 @@
|
||||||
let
|
let
|
||||||
keyvalue = key: value:
|
keyvalue = key: value:
|
||||||
assert builtins.isString key;
|
assert builtins.isString key;
|
||||||
if builtins.isAttrs value then
|
if builtins.isAttrs value
|
||||||
builtins.trace "Skipping ${key} as it is a set" ""
|
then builtins.trace "Skipping ${key} as it is a set" ""
|
||||||
else if value == "" || value == [ ] || value == false then
|
else if value == "" || value == [] || value == false
|
||||||
""
|
then ""
|
||||||
else if value == true then
|
else if value == true
|
||||||
key
|
then key
|
||||||
else
|
else ''${key}="${toString value}"'';
|
||||||
''${key}="${toString value}"'';
|
|
||||||
in rec {
|
in rec {
|
||||||
toHTML = elem:
|
toHTML = elem:
|
||||||
if builtins.isString elem then
|
if builtins.isString elem
|
||||||
elem
|
then elem
|
||||||
else if builtins.isList elem then
|
else if builtins.isList elem
|
||||||
builtins.toString (map toHTML elem)
|
then builtins.toString (map toHTML elem)
|
||||||
else
|
else "<${elem.tag} ${writeAttrs elem.attrs or {}}>${
|
||||||
"<${elem.tag} ${writeAttrs elem.attrs or { }}>${
|
|
||||||
toHTML elem.child or ""
|
toHTML elem.child or ""
|
||||||
}</${elem.tag}>";
|
}</${elem.tag}>";
|
||||||
|
|
||||||
writeAttrs = attrs:
|
writeAttrs = attrs:
|
||||||
toString (builtins.filter (value: value != "") (builtins.attrValues
|
toString (builtins.filter (value: value != "") (builtins.attrValues
|
||||||
(builtins.mapAttrs (key: value:
|
(builtins.mapAttrs (key: value:
|
||||||
if (builtins.isPath value) then
|
if (builtins.isPath value)
|
||||||
keyvalue key (baseNameOf value)
|
then keyvalue key (baseNameOf value)
|
||||||
else if (builtins.substring 0 2 key) == "__" then
|
else if (builtins.substring 0 2 key) == "__"
|
||||||
""
|
then ""
|
||||||
else
|
else keyvalue key value)
|
||||||
keyvalue key value) attrs)));
|
attrs)));
|
||||||
|
|
||||||
tag = t:
|
tag = t: ({
|
||||||
({
|
|
||||||
tag = t;
|
tag = t;
|
||||||
attrs = {};
|
attrs = {};
|
||||||
} // baseTag);
|
}
|
||||||
|
// baseTag);
|
||||||
|
|
||||||
baseTag = {
|
baseTag = {
|
||||||
__toString = self: toString (self "");
|
__toString = self: toString (self "");
|
||||||
__functor = self: child:
|
__functor = self: child: (
|
||||||
(if !(isTag child) then
|
if !(isTag child)
|
||||||
(if isSet child then
|
then
|
||||||
incorporateAttrs self child
|
(
|
||||||
|
if isSet child
|
||||||
|
then incorporateAttrs self child
|
||||||
else
|
else
|
||||||
throw "tag child must be tag, list, or string, got ${
|
throw "tag child must be tag, list, or string, got ${
|
||||||
builtins.typeOf child
|
builtins.typeOf child
|
||||||
}")
|
}"
|
||||||
|
)
|
||||||
else
|
else
|
||||||
self // {
|
self
|
||||||
|
// {
|
||||||
inherit child;
|
inherit child;
|
||||||
__toString = toHTML;
|
__toString = toHTML;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
incorporateAttrs = self: attrs: self // ({ attrs = self.attrs // attrs; });
|
incorporateAttrs = self: attrs: self // {attrs = self.attrs // attrs;};
|
||||||
|
|
||||||
isSet = a: builtins.isAttrs a && !a ? __toString;
|
isSet = a: builtins.isAttrs a && !a ? __toString;
|
||||||
|
|
||||||
isTag = tag:
|
isTag = tag: (builtins.isString tag
|
||||||
(builtins.isString tag || builtins.isList tag
|
|| builtins.isList tag
|
||||||
|| (tag ? __toString && builtins.isFunction tag.__toString));
|
|| (tag ? __toString && builtins.isFunction tag.__toString));
|
||||||
|
|
||||||
addToHead = page: heads:
|
addToHead = page: heads:
|
||||||
page // {
|
page
|
||||||
child = map
|
// {
|
||||||
(e: if e.tag == "head" then e // { child = e.child ++ heads; } else e)
|
child =
|
||||||
|
map
|
||||||
|
(e:
|
||||||
|
if e.tag == "head"
|
||||||
|
then e // {child = e.child ++ heads;}
|
||||||
|
else e)
|
||||||
page.child;
|
page.child;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ stdenv, ... }:
|
{stdenv, ...}: raw: let
|
||||||
raw:
|
site = import ./site.nix;
|
||||||
let site = import ./site.nix;
|
in
|
||||||
in stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "site";
|
name = "site";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
|
|
154
nixite/md.nix
154
nixite/md.nix
|
@ -1,28 +1,31 @@
|
||||||
let elems = import ./elems.nix;
|
let
|
||||||
|
elems = import ./elems.nix;
|
||||||
in rec {
|
in rec {
|
||||||
readMd = md:
|
readMd = md:
|
||||||
if builtins.isPath md then
|
if builtins.isPath md
|
||||||
processMd (builtins.readFile md)
|
then processMd (builtins.readFile md)
|
||||||
else
|
else processMd md;
|
||||||
processMd md;
|
|
||||||
|
|
||||||
processMd = processStr;
|
processMd = processStr;
|
||||||
|
|
||||||
recReadMd = root:
|
recReadMd = root:
|
||||||
assert builtins.isPath root;
|
assert builtins.isPath root;
|
||||||
builtins.mapAttrs (path: type:
|
builtins.mapAttrs (path: type:
|
||||||
if type == "directory" then
|
if type == "directory"
|
||||||
recReadMd (root + (/. + path))
|
then recReadMd (root + (/. + path))
|
||||||
else if type == "regular" then
|
else if type == "regular"
|
||||||
mdToPage (root + (/. + path))
|
then mdToPage (root + (/. + path))
|
||||||
else
|
else throw "Cannot read ${path}, file type ${type}") (builtins.readDir root);
|
||||||
throw "Cannot read ${path}, file type ${type}") (builtins.readDir root);
|
|
||||||
|
|
||||||
recFixAppendix = site:
|
recFixAppendix = site:
|
||||||
builtins.listToAttrs (builtins.attrValues (builtins.mapAttrs (name: value: {
|
builtins.listToAttrs (builtins.attrValues (builtins.mapAttrs (name: value: {
|
||||||
name = fixAppendix name;
|
name = fixAppendix name;
|
||||||
value = if builtins.isAttrs value then recFixAppendix value else value;
|
value =
|
||||||
}) site));
|
if builtins.isAttrs value
|
||||||
|
then recFixAppendix value
|
||||||
|
else value;
|
||||||
|
})
|
||||||
|
site));
|
||||||
|
|
||||||
fixAppendix = builtins.replaceStrings [".md"] [".html"];
|
fixAppendix = builtins.replaceStrings [".md"] [".html"];
|
||||||
|
|
||||||
|
@ -31,27 +34,22 @@ in rec {
|
||||||
mdToPage = md:
|
mdToPage = md:
|
||||||
elems.Doc {} [[(elems.title {} "markdown file")] (readMd md)];
|
elems.Doc {} [[(elems.title {} "markdown file")] (readMd md)];
|
||||||
|
|
||||||
code = block:
|
|
||||||
matchThen "(```)(.*)(```)" block (m: elems.code (builtins.elemAt m 1));
|
|
||||||
|
|
||||||
list = block:
|
list = block:
|
||||||
matchThen (''
|
matchThen "(- .+\n)*(- .+\n?)"
|
||||||
(- .+
|
block (m: elems.List (splitList block));
|
||||||
)*(- .+
|
|
||||||
?)'') block (m: elems.List (splitList block));
|
|
||||||
|
|
||||||
splitList = block:
|
splitList = block:
|
||||||
map (listItem) (builtins.filter (s: builtins.isString s && s != "")
|
map listItem (builtins.filter (s: builtins.isString s && s != "")
|
||||||
(builtins.split "\n" block));
|
(builtins.split "\n" block));
|
||||||
|
|
||||||
listItem = str:
|
listItem = str: let
|
||||||
let
|
|
||||||
li = builtins.match "- (.*)" str;
|
li = builtins.match "- (.*)" str;
|
||||||
checkbox = builtins.match "- \\[(.)] (.*)" str;
|
checkbox = builtins.match "- \\[(.)] (.*)" str;
|
||||||
checked = builtins.elemAt checkbox 0;
|
checked = builtins.elemAt checkbox 0;
|
||||||
content = builtins.elemAt checkbox 1;
|
content = builtins.elemAt checkbox 1;
|
||||||
in if checkbox == null then
|
in
|
||||||
li
|
if checkbox == null
|
||||||
|
then li
|
||||||
else [
|
else [
|
||||||
(elems.input {
|
(elems.input {
|
||||||
type = "checkbox";
|
type = "checkbox";
|
||||||
|
@ -61,28 +59,41 @@ in rec {
|
||||||
content
|
content
|
||||||
];
|
];
|
||||||
|
|
||||||
replace = regex: apply: block:
|
replace = regex: apply: block: (let
|
||||||
(let
|
|
||||||
m = builtins.match regex block;
|
m = builtins.match regex block;
|
||||||
before = let v = builtins.elemAt m 0; in if v == null then "" else v;
|
before = let
|
||||||
|
v = builtins.elemAt m 0;
|
||||||
|
in
|
||||||
|
if v == null
|
||||||
|
then ""
|
||||||
|
else v;
|
||||||
after = toString (builtins.elemAt m (matchCount - 1));
|
after = toString (builtins.elemAt m (matchCount - 1));
|
||||||
matchCount = builtins.length m;
|
matchCount = builtins.length m;
|
||||||
in if m == null then
|
in
|
||||||
block
|
if m == null
|
||||||
else
|
then block
|
||||||
(replace regex apply before) + (apply m) + after);
|
else (replace regex apply before) + (apply m) + after);
|
||||||
|
|
||||||
rule = matcher: apply: blocks:
|
rule = matcher: apply: blocks:
|
||||||
map (b: if builtins.isString b then replace matcher apply b else b) blocks;
|
map (b:
|
||||||
|
if builtins.isString b
|
||||||
|
then replace matcher apply b
|
||||||
|
else b)
|
||||||
|
blocks;
|
||||||
|
|
||||||
applyRules = i: rules: input:
|
applyRules = i: rules: input: let
|
||||||
let
|
group =
|
||||||
group = if builtins.isString input then [ input ] else input;
|
if builtins.isString input
|
||||||
|
then [input]
|
||||||
|
else input;
|
||||||
len = builtins.length rules;
|
len = builtins.length rules;
|
||||||
rule = builtins.elemAt rules i;
|
rule = builtins.elemAt rules i;
|
||||||
next = i + 1;
|
next = i + 1;
|
||||||
in assert i < len;
|
in
|
||||||
if next < len then rule (applyRules next rules group) else rule group;
|
assert i < len;
|
||||||
|
if next < len
|
||||||
|
then rule (applyRules next rules group)
|
||||||
|
else rule group;
|
||||||
|
|
||||||
basicRule = matcher: elem: rule matcher (m: elem (builtins.elemAt m 1));
|
basicRule = matcher: elem: rule matcher (m: elem (builtins.elemAt m 1));
|
||||||
|
|
||||||
|
@ -96,60 +107,27 @@ in rec {
|
||||||
(basicRule (wrap "~~") elems.del)
|
(basicRule (wrap "~~") elems.del)
|
||||||
(basicRule (wrap "\\*\\*") elems.strong)
|
(basicRule (wrap "\\*\\*") elems.strong)
|
||||||
(basicRule (wrapBreak "__") elems.strong)
|
(basicRule (wrapBreak "__") elems.strong)
|
||||||
(rule (contains "\\[(.*)]\\((.*)\\)") (m:
|
(rule (contains "\\[(.*)]\\((.*)\\)") (m: let
|
||||||
let
|
|
||||||
href = builtins.elemAt m 2;
|
href = builtins.elemAt m 2;
|
||||||
text = builtins.elemAt m 1;
|
text = builtins.elemAt m 1;
|
||||||
in (elems.a href text)))
|
in (elems.a href text)))
|
||||||
(rule (''
|
(rule "(.*\n)([^-][^\n]+\n)((- [^\n]+\n)+)(.*)" (
|
||||||
(.*
|
l: (elems.ul (basicRule "(.*\n)?- ([^\n]+)\n(.*)" (m:
|
||||||
)([^-][^
|
elems.li (basicRule "()\\[(.)](.*)" (check:
|
||||||
]+
|
|
||||||
)((- [^
|
|
||||||
]+
|
|
||||||
)+)(.*)'') (
|
|
||||||
|
|
||||||
l:
|
|
||||||
(elems.ul (basicRule (''
|
|
||||||
(.*
|
|
||||||
)?- ([^
|
|
||||||
]+)
|
|
||||||
(.*)'') (m:
|
|
||||||
elems.li (basicRule ("()\\[(.)](.*)") (check:
|
|
||||||
elems.input {
|
elems.input {
|
||||||
type = "checkbox";
|
type = "checkbox";
|
||||||
checked = check != " ";
|
checked = check != " ";
|
||||||
disabled = true;
|
disabled = true;
|
||||||
}) [m])) [(builtins.elemAt l 2)]))
|
}) [m])) [(builtins.elemAt l 2)]))
|
||||||
|
|
||||||
))
|
))
|
||||||
(basicRule (''
|
(basicRule "(.*\n\n)?(.+)\n(.*)?" elems.p)
|
||||||
(.*
|
(basicRule "(.*\n\n)?```(.*)```(.*)?" (elems.textarea {readonly = true;}))
|
||||||
|
(basicRule (containsBreak "###### ([^\n]+)") (elems.h6))
|
||||||
)?(.+)
|
(basicRule (containsBreak "##### ([^\n]+)") (elems.h5))
|
||||||
(.*)?'') elems.p)
|
(basicRule (containsBreak "#### ([^\n]+)") (elems.h4))
|
||||||
(basicRule (''
|
(basicRule (containsBreak "### ([^\n]+)") (elems.h3))
|
||||||
(.*
|
(basicRule (containsBreak "## ([^\n]+)") (elems.h2))
|
||||||
|
(basicRule (containsBreak "# ([^\n]+)") (elems.h1))
|
||||||
)?```(.*)```(.*)?'') (elems.textarea { readonly = true; }))
|
|
||||||
(basicRule (containsBreak ''
|
|
||||||
###### ([^
|
|
||||||
]+)'') (elems.h6))
|
|
||||||
(basicRule (containsBreak ''
|
|
||||||
##### ([^
|
|
||||||
]+)'') (elems.h5))
|
|
||||||
(basicRule (containsBreak ''
|
|
||||||
#### ([^
|
|
||||||
]+)'') (elems.h4))
|
|
||||||
(basicRule (containsBreak ''
|
|
||||||
### ([^
|
|
||||||
]+)'') (elems.h3))
|
|
||||||
(basicRule (containsBreak ''
|
|
||||||
## ([^
|
|
||||||
]+)'') (elems.h2))
|
|
||||||
(basicRule (containsBreak ''
|
|
||||||
# ([^
|
|
||||||
]+)'') (elems.h1))
|
|
||||||
(basicRule (containsBreak "<(${linkmatcher})>") (m: elems.a m m))
|
(basicRule (containsBreak "<(${linkmatcher})>") (m: elems.a m m))
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -160,10 +138,11 @@ in rec {
|
||||||
containsBreak = matcher: "(.*[[:space:]])?${matcher}(.*)";
|
containsBreak = matcher: "(.*[[:space:]])?${matcher}(.*)";
|
||||||
wrapBreak = matcher: containsBreak "${matcher}([^${matcher}]+)${matcher}";
|
wrapBreak = matcher: containsBreak "${matcher}([^${matcher}]+)${matcher}";
|
||||||
|
|
||||||
matchThen = matcher: block: func:
|
matchThen = matcher: block: func: let
|
||||||
let m = builtins.match matcher block;
|
m = builtins.match matcher block;
|
||||||
in if m == null then
|
in
|
||||||
dontMatch block
|
if m == null
|
||||||
|
then dontMatch block
|
||||||
else {
|
else {
|
||||||
matched = true;
|
matched = true;
|
||||||
block = func m;
|
block = func m;
|
||||||
|
@ -173,5 +152,4 @@ in rec {
|
||||||
matched = false;
|
matched = false;
|
||||||
inherit block;
|
inherit block;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
134
nixite/site.nix
134
nixite/site.nix
|
@ -3,12 +3,16 @@ let
|
||||||
elems = import ./elems.nix;
|
elems = import ./elems.nix;
|
||||||
style = import ./style.nix;
|
style = import ./style.nix;
|
||||||
in rec {
|
in rec {
|
||||||
prepare = { favicon ? null, styles ? { }, }:
|
prepare = {
|
||||||
site:
|
favicon ? null,
|
||||||
let
|
styles ? {},
|
||||||
|
}: site: let
|
||||||
nullFn = p: p;
|
nullFn = p: p;
|
||||||
allStyles = styles // getStyles site;
|
allStyles = styles // getStyles site;
|
||||||
doFavicon = if favicon != null then (applyFavicon favicon) else nullFn;
|
doFavicon =
|
||||||
|
if favicon != null
|
||||||
|
then (applyFavicon favicon)
|
||||||
|
else nullFn;
|
||||||
in (extractPaths (extractLinks (applyStyle allStyles (doFavicon site))));
|
in (extractPaths (extractLinks (applyStyle allStyles (doFavicon site))));
|
||||||
|
|
||||||
getStyles = site:
|
getStyles = site:
|
||||||
|
@ -17,12 +21,11 @@ in rec {
|
||||||
|
|
||||||
flatten = site:
|
flatten = site:
|
||||||
map (page:
|
map (page:
|
||||||
if builtins.isAttrs page && page ? "__toString" then
|
if builtins.isAttrs page && page ? "__toString"
|
||||||
page
|
then page
|
||||||
else if builtins.isAttrs page then
|
else if builtins.isAttrs page
|
||||||
flatten page
|
then flatten page
|
||||||
else
|
else page) (builtins.attrValues site);
|
||||||
page) (builtins.attrValues site);
|
|
||||||
|
|
||||||
applyStyle = style: site: ((linkStyle site) // {"style.css" = style;});
|
applyStyle = style: site: ((linkStyle site) // {"style.css" = style;});
|
||||||
|
|
||||||
|
@ -30,14 +33,13 @@ in rec {
|
||||||
eachPage site
|
eachPage site
|
||||||
(content: html.addToHead content [(elems.Stylesheet "/style.css")]);
|
(content: html.addToHead content [(elems.Stylesheet "/style.css")]);
|
||||||
|
|
||||||
eachPage = site: callback:
|
eachPage = site: callback: (builtins.mapAttrs (name: content:
|
||||||
(builtins.mapAttrs (name: content:
|
if builtins.isAttrs content && content ? "__toString"
|
||||||
if builtins.isAttrs content && content ? "__toString" then
|
then callback content
|
||||||
callback content
|
else if builtins.isAttrs content
|
||||||
else if builtins.isAttrs content then
|
then eachPage content callback
|
||||||
eachPage content callback
|
else content)
|
||||||
else
|
site);
|
||||||
content) site);
|
|
||||||
|
|
||||||
applyFavicon = icon: site:
|
applyFavicon = icon: site:
|
||||||
eachPage site (content:
|
eachPage site (content:
|
||||||
|
@ -49,19 +51,21 @@ in rec {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
extractPaths = content:
|
extractPaths = content:
|
||||||
switchPaths content // {
|
switchPaths content
|
||||||
|
// {
|
||||||
static = (content.static or {}) // getPaths content;
|
static = (content.static or {}) // getPaths content;
|
||||||
};
|
};
|
||||||
|
|
||||||
extractLinks = content:
|
extractLinks = content:
|
||||||
switchLinks content // {
|
switchLinks content
|
||||||
|
// {
|
||||||
static = (content.static or {}) // getLinks content;
|
static = (content.static or {}) // getLinks content;
|
||||||
};
|
};
|
||||||
|
|
||||||
isLink = value:
|
isLink = value:
|
||||||
builtins.isAttrs value && value ? type && value.type == "link";
|
builtins.isAttrs value && value ? type && value.type == "link";
|
||||||
|
|
||||||
switchLinks = runDeep (isLink) (value: "/static/" + value.name);
|
switchLinks = runDeep isLink (value: "/static/" + value.name);
|
||||||
|
|
||||||
getLinks = content: (builtins.listToAttrs (getLinksKV content));
|
getLinks = content: (builtins.listToAttrs (getLinksKV content));
|
||||||
|
|
||||||
|
@ -72,19 +76,30 @@ in rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
runLink = f:
|
runLink = f:
|
||||||
if !builtins.isFunction f then
|
if !builtins.isFunction f
|
||||||
null
|
then null
|
||||||
else
|
else
|
||||||
(let res = f { }; in (if !builtins.isAttrs res then null else res));
|
(let
|
||||||
|
res = f {};
|
||||||
|
in (
|
||||||
|
if !builtins.isAttrs res
|
||||||
|
then null
|
||||||
|
else res
|
||||||
|
));
|
||||||
|
|
||||||
runDeep = when: do: set:
|
runDeep = when: do: set: (
|
||||||
(if builtins.isAttrs set then
|
if builtins.isAttrs set
|
||||||
|
then
|
||||||
builtins.mapAttrs
|
builtins.mapAttrs
|
||||||
(key: value: if when value then do value else runDeep when do value) set
|
(key: value:
|
||||||
else if builtins.isList set then
|
if when value
|
||||||
(map (runDeep when do) set)
|
then do value
|
||||||
else
|
else runDeep when do value)
|
||||||
set);
|
set
|
||||||
|
else if builtins.isList set
|
||||||
|
then (map (runDeep when do) set)
|
||||||
|
else set
|
||||||
|
);
|
||||||
|
|
||||||
switchPaths = runDeep builtins.isPath (value: "/static/" + baseNameOf value);
|
switchPaths = runDeep builtins.isPath (value: "/static/" + baseNameOf value);
|
||||||
|
|
||||||
|
@ -96,35 +111,60 @@ in rec {
|
||||||
value = v: v;
|
value = v: v;
|
||||||
};
|
};
|
||||||
|
|
||||||
getAllKV = { when, key, value }@params:
|
getAllKV = {
|
||||||
path:
|
when,
|
||||||
(if when path then [{
|
key,
|
||||||
|
value,
|
||||||
|
} @ params: path: (
|
||||||
|
if when path
|
||||||
|
then [
|
||||||
|
{
|
||||||
name = key path;
|
name = key path;
|
||||||
value = value path;
|
value = value path;
|
||||||
}] else if builtins.isAttrs path then
|
}
|
||||||
|
]
|
||||||
|
else if builtins.isAttrs path
|
||||||
|
then
|
||||||
builtins.concatMap (getAllKV params) (builtins.attrValues
|
builtins.concatMap (getAllKV params) (builtins.attrValues
|
||||||
(builtins.mapAttrs
|
(builtins.mapAttrs
|
||||||
(n: v: if (builtins.substring 0 2 n == "__") then null else v) path))
|
(n: v:
|
||||||
else if builtins.isList path then
|
if (builtins.substring 0 2 n == "__")
|
||||||
builtins.concatMap (getAllKV params) path
|
then null
|
||||||
else
|
else v)
|
||||||
[ ]);
|
path))
|
||||||
|
else if builtins.isList path
|
||||||
|
then builtins.concatMap (getAllKV params) path
|
||||||
|
else []
|
||||||
|
);
|
||||||
|
|
||||||
link = { name, content }@page: page // { type = "link"; };
|
link = {
|
||||||
|
name,
|
||||||
|
content,
|
||||||
|
} @ page:
|
||||||
|
page // {type = "link";};
|
||||||
|
|
||||||
copyTo = prefix: site:
|
copyTo = prefix: site:
|
||||||
builtins.toString (builtins.attrValues (builtins.mapAttrs (name: content:
|
builtins.toString (builtins.attrValues (builtins.mapAttrs (name: content:
|
||||||
if builtins.isString content then ''
|
if builtins.isString content
|
||||||
|
then ''
|
||||||
cp ${builtins.toFile name content} ${prefix}/${name}
|
cp ${builtins.toFile name content} ${prefix}/${name}
|
||||||
'' else if builtins.isPath content then ''
|
''
|
||||||
|
else if builtins.isPath content
|
||||||
|
then ''
|
||||||
cp -r ${content} ${prefix}/${name}
|
cp -r ${content} ${prefix}/${name}
|
||||||
'' else if builtins.isAttrs content && content ? "__toString" then ''
|
''
|
||||||
|
else if builtins.isAttrs content && content ? "__toString"
|
||||||
|
then ''
|
||||||
cp ${builtins.toFile name (toString content)} ${prefix}/${name}
|
cp ${builtins.toFile name (toString content)} ${prefix}/${name}
|
||||||
'' else if builtins.isAttrs content then ''
|
''
|
||||||
|
else if builtins.isAttrs content
|
||||||
|
then ''
|
||||||
mkdir -p ${prefix}/${name}
|
mkdir -p ${prefix}/${name}
|
||||||
${copyTo "${prefix}/${name}" content}
|
${copyTo "${prefix}/${name}" content}
|
||||||
'' else
|
''
|
||||||
|
else
|
||||||
throw "Site page must be string, path or attrset, but got ${
|
throw "Site page must be string, path or attrset, but got ${
|
||||||
builtins.typeOf content
|
builtins.typeOf content
|
||||||
}: [${toString content}]") site));
|
}: [${toString content}]")
|
||||||
|
site));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
let
|
let
|
||||||
|
|
||||||
styleToString = identifier: styles:
|
styleToString = identifier: styles:
|
||||||
if !builtins.isAttrs styles then
|
if !builtins.isAttrs styles
|
||||||
""
|
then ""
|
||||||
else if styles == { } then
|
else if styles == {}
|
||||||
""
|
then ""
|
||||||
else
|
else
|
||||||
assert builtins.isString identifier; ''
|
assert builtins.isString identifier; ''
|
||||||
${identifier} {
|
${identifier} {
|
||||||
|
@ -16,24 +15,31 @@ let
|
||||||
'';
|
'';
|
||||||
|
|
||||||
getStyle = element:
|
getStyle = element:
|
||||||
if builtins.isAttrs element && element.attrs ? __id then
|
if builtins.isAttrs element && element.attrs ? __id
|
||||||
|
then
|
||||||
({
|
({
|
||||||
${element.attrs.__id} = element.attrs.style or {};
|
${element.attrs.__id} = element.attrs.style or {};
|
||||||
} // (if element.attrs ? __extends then {
|
}
|
||||||
|
// (
|
||||||
|
if element.attrs ? __extends
|
||||||
|
then {
|
||||||
${element.attrs.__extends.attrs.__id or element.attrs.__extends.tag} =
|
${element.attrs.__extends.attrs.__id or element.attrs.__extends.tag} =
|
||||||
element.attrs.__extends.attrs.style or {};
|
element.attrs.__extends.attrs.style or {};
|
||||||
} else
|
}
|
||||||
{ }))
|
else {}
|
||||||
else
|
))
|
||||||
{ };
|
else {};
|
||||||
|
|
||||||
getStyles = element:
|
getStyles = element:
|
||||||
(getStyle element) // (if builtins.isList element then
|
(getStyle element)
|
||||||
getStylesFromList element
|
// (
|
||||||
else if element ? child then
|
if builtins.isList element
|
||||||
getStyles element.child
|
then getStylesFromList element
|
||||||
else
|
else if element ? child
|
||||||
{ }) // {
|
then getStyles element.child
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
// {
|
||||||
__toString = stylesToString;
|
__toString = stylesToString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,7 +48,8 @@ let
|
||||||
(map getStyles elements);
|
(map getStyles elements);
|
||||||
|
|
||||||
mkProps = tag: class: props:
|
mkProps = tag: class: props:
|
||||||
props // {
|
props
|
||||||
|
// {
|
||||||
__id = "${tag.tag}.${class}";
|
__id = "${tag.tag}.${class}";
|
||||||
__extends = tag;
|
__extends = tag;
|
||||||
class = (tag.attrs.class or []) ++ [class] ++ (props.class or []);
|
class = (tag.attrs.class or []) ++ [class] ++ (props.class or []);
|
||||||
|
@ -50,8 +57,7 @@ let
|
||||||
|
|
||||||
stylesToString = styles:
|
stylesToString = styles:
|
||||||
builtins.concatStringsSep ""
|
builtins.concatStringsSep ""
|
||||||
(builtins.attrValues (builtins.mapAttrs (styleToString) styles));
|
(builtins.attrValues (builtins.mapAttrs styleToString styles));
|
||||||
|
|
||||||
in {
|
in {
|
||||||
inherit getStyle getStyles stylesToString;
|
inherit getStyle getStyles stylesToString;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{ it, ... }:
|
{it, ...}: let
|
||||||
let
|
|
||||||
elems = import ../nixite/elems.nix;
|
elems = import ../nixite/elems.nix;
|
||||||
style = import ../nixite/style.nix;
|
style = import ../nixite/style.nix;
|
||||||
html = import ../nixite/html.nix;
|
html = import ../nixite/html.nix;
|
||||||
in with elems; [
|
in
|
||||||
|
with elems; [
|
||||||
(it "makes a p tag" {
|
(it "makes a p tag" {
|
||||||
expected = html.tag "p" {} "foobar";
|
expected = html.tag "p" {} "foobar";
|
||||||
actual = p {} "foobar";
|
actual = p {} "foobar";
|
||||||
|
@ -49,8 +49,11 @@ in with elems; [
|
||||||
|
|
||||||
(it "lets you extend the a tag" {
|
(it "lets you extend the a tag" {
|
||||||
expected = ["linky"];
|
expected = ["linky"];
|
||||||
actual = ((style.component a "linky" { }) "https://example.com"
|
actual =
|
||||||
"example").attrs.class;
|
((style.component a "linky" {}) "https://example.com"
|
||||||
|
"example")
|
||||||
|
.attrs
|
||||||
|
.class;
|
||||||
asString = true;
|
asString = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
{ it, ... }:
|
{it, ...}: let
|
||||||
let html = import ../nixite/html.nix;
|
html = import ../nixite/html.nix;
|
||||||
in with html; [
|
in
|
||||||
|
with html; [
|
||||||
(it "keeps info in the tag" (let p = tag "p";
|
(it "keeps info in the tag" (let
|
||||||
|
p = tag "p";
|
||||||
in {
|
in {
|
||||||
actual = p.tag;
|
actual = p.tag;
|
||||||
expected = "p";
|
expected = "p";
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "keeps attr info in the tag" (let p = tag "p" { class = ""; };
|
(it "keeps attr info in the tag" (let
|
||||||
|
p = tag "p" {class = "";};
|
||||||
in {
|
in {
|
||||||
actual = p.attrs;
|
actual = p.attrs;
|
||||||
expected = {class = "";};
|
expected = {class = "";};
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "keeps tag after setting attrs" (let p = tag "p" { class = ""; };
|
(it "keeps tag after setting attrs" (let
|
||||||
|
p = tag "p" {class = "";};
|
||||||
in {
|
in {
|
||||||
actual = p.tag;
|
actual = p.tag;
|
||||||
expected = "p";
|
expected = "p";
|
||||||
|
@ -30,7 +33,8 @@ in with html; [
|
||||||
removeDunders = true;
|
removeDunders = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
(it "makes element" (let para = (tag "p" { });
|
(it "makes element" (let
|
||||||
|
para = tag "p" {};
|
||||||
in {
|
in {
|
||||||
expected = "p";
|
expected = "p";
|
||||||
actual = para.tag;
|
actual = para.tag;
|
||||||
|
@ -38,7 +42,7 @@ in with html; [
|
||||||
|
|
||||||
(it "keeps attrs on element" (let
|
(it "keeps attrs on element" (let
|
||||||
attrs = {style = {foo = "bar";};};
|
attrs = {style = {foo = "bar";};};
|
||||||
para = (tag "p" attrs);
|
para = tag "p" attrs;
|
||||||
in {
|
in {
|
||||||
expected = attrs;
|
expected = attrs;
|
||||||
actual = para.attrs;
|
actual = para.attrs;
|
||||||
|
@ -46,7 +50,7 @@ in with html; [
|
||||||
|
|
||||||
(it "makes renderable element" (let
|
(it "makes renderable element" (let
|
||||||
attrs = {style = {foo = "bar";};};
|
attrs = {style = {foo = "bar";};};
|
||||||
para = (tag "p" attrs);
|
para = tag "p" attrs;
|
||||||
in {
|
in {
|
||||||
expected = "<p ></p>";
|
expected = "<p ></p>";
|
||||||
actual = toString (para "");
|
actual = toString (para "");
|
||||||
|
@ -54,7 +58,7 @@ in with html; [
|
||||||
|
|
||||||
(it "keeps tag" (let
|
(it "keeps tag" (let
|
||||||
attrs = {style = {foo = "bar";};};
|
attrs = {style = {foo = "bar";};};
|
||||||
para = (tag "p" attrs);
|
para = tag "p" attrs;
|
||||||
in {
|
in {
|
||||||
expected = "p";
|
expected = "p";
|
||||||
actual = (para "").tag;
|
actual = (para "").tag;
|
||||||
|
@ -62,25 +66,28 @@ in with html; [
|
||||||
|
|
||||||
(it "keeps style" (let
|
(it "keeps style" (let
|
||||||
attrs = {style = {foo = "bar";};};
|
attrs = {style = {foo = "bar";};};
|
||||||
para = (tag "p" attrs);
|
para = tag "p" attrs;
|
||||||
in {
|
in {
|
||||||
expected = {foo = "bar";};
|
expected = {foo = "bar";};
|
||||||
actual = (para "").attrs.style;
|
actual = (para "").attrs.style;
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "needs no args to make string" (let p = tag "p";
|
(it "needs no args to make string" (let
|
||||||
|
p = tag "p";
|
||||||
in {
|
in {
|
||||||
actual = toString p;
|
actual = toString p;
|
||||||
expected = "<p ></p>";
|
expected = "<p ></p>";
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "needs no content to make string" (let p = tag "p";
|
(it "needs no content to make string" (let
|
||||||
|
p = tag "p";
|
||||||
in {
|
in {
|
||||||
actual = toString (p {class = "foobar";});
|
actual = toString (p {class = "foobar";});
|
||||||
expected = ''<p class="foobar"></p>'';
|
expected = ''<p class="foobar"></p>'';
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "can take many sets of props" (let p = tag "p";
|
(it "can take many sets of props" (let
|
||||||
|
p = tag "p";
|
||||||
in {
|
in {
|
||||||
actual = toString (p {class = "foobar";} {style = "a style";});
|
actual = toString (p {class = "foobar";} {style = "a style";});
|
||||||
expected = ''<p class="foobar" style="a style"></p>'';
|
expected = ''<p class="foobar" style="a style"></p>'';
|
||||||
|
@ -88,39 +95,40 @@ in with html; [
|
||||||
|
|
||||||
(it "works recursively" (let
|
(it "works recursively" (let
|
||||||
attrs = {style = {foo = "bar";};};
|
attrs = {style = {foo = "bar";};};
|
||||||
para = (tag "p" attrs);
|
para = tag "p" attrs;
|
||||||
a = (tag "a" { });
|
a = tag "a" {};
|
||||||
in {
|
in {
|
||||||
expected = "<p ><a >hello</a></p>";
|
expected = "<p ><a >hello</a></p>";
|
||||||
actual = toString (para (a "hello"));
|
actual = toString (para (a "hello"));
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "throws with function child" ({
|
(it "throws with function child" {
|
||||||
actual = toString (tag "p" (i: ""));
|
actual = toString (tag "p" (i: ""));
|
||||||
throws = true;
|
throws = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "throws with a number" ({
|
(it "throws with a number" {
|
||||||
actual = toString (tag "p" 5);
|
actual = toString (tag "p" 5);
|
||||||
throws = true;
|
throws = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "throws with a bool" ({
|
(it "throws with a bool" {
|
||||||
actual = toString (tag "p" true);
|
actual = toString (tag "p" true);
|
||||||
throws = true;
|
throws = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "throws with a null" ({
|
(it "throws with a null" {
|
||||||
actual = toString (tag "p" null);
|
actual = toString (tag "p" null);
|
||||||
throws = true;
|
throws = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "concatinates classes" {
|
(it "concatinates classes" {
|
||||||
actual = toString (tag "p" {class = ["class1" "class2"];} "Hello");
|
actual = toString (tag "p" {class = ["class1" "class2"];} "Hello");
|
||||||
expected = ''<p class="class1 class2">Hello</p>'';
|
expected = ''<p class="class1 class2">Hello</p>'';
|
||||||
})
|
})
|
||||||
|
|
||||||
(it "applies style" (let page = tag "html" { } [ (tag "head" { } [ "foo" ]) ];
|
(it "applies style" (let
|
||||||
|
page = tag "html" {} [(tag "head" {} ["foo"])];
|
||||||
in {
|
in {
|
||||||
actual = addToHead page ["bar"];
|
actual = addToHead page ["bar"];
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -131,12 +139,11 @@ in with html; [
|
||||||
removeDunders = true;
|
removeDunders = true;
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "renders on / off attrs" ({
|
(it "renders on / off attrs" {
|
||||||
actual = toString (tag "p" {
|
actual = toString (tag "p" {
|
||||||
on = true;
|
on = true;
|
||||||
off = false;
|
off = false;
|
||||||
});
|
});
|
||||||
expected = "<p on></p>";
|
expected = "<p on></p>";
|
||||||
}))
|
})
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
{ it, ... }:
|
{it, ...}: let
|
||||||
let
|
|
||||||
md = import ../nixite/md.nix;
|
md = import ../nixite/md.nix;
|
||||||
elems = import ../nixite/elems.nix;
|
elems = import ../nixite/elems.nix;
|
||||||
in with md; [
|
in
|
||||||
|
with md; [
|
||||||
(it "matches a list of one element" ({
|
(it "matches a list of one element" {
|
||||||
actual = list ''
|
actual = list ''
|
||||||
- something
|
- something
|
||||||
'';
|
'';
|
||||||
|
@ -13,9 +12,9 @@ in with md; [
|
||||||
block = elems.List ["something"];
|
block = elems.List ["something"];
|
||||||
};
|
};
|
||||||
asJSON = true;
|
asJSON = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "makes a list of many elements" ({
|
(it "makes a list of many elements" {
|
||||||
actual = list ''
|
actual = list ''
|
||||||
- something
|
- something
|
||||||
- something else
|
- something else
|
||||||
|
@ -25,9 +24,9 @@ in with md; [
|
||||||
block = elems.List ["something" "something else"];
|
block = elems.List ["something" "something else"];
|
||||||
};
|
};
|
||||||
asJSON = true;
|
asJSON = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "makes a list of many checkboxes" ({
|
(it "makes a list of many checkboxes" {
|
||||||
actual = list ''
|
actual = list ''
|
||||||
- [ ] something
|
- [ ] something
|
||||||
- [X] something else
|
- [X] something else
|
||||||
|
@ -54,9 +53,9 @@ in with md; [
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
asJSON = true;
|
asJSON = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "matches a list with no whitespace around" ({
|
(it "matches a list with no whitespace around" {
|
||||||
actual = list ''
|
actual = list ''
|
||||||
- something
|
- something
|
||||||
- something else'';
|
- something else'';
|
||||||
|
@ -65,9 +64,10 @@ in with md; [
|
||||||
block = elems.List ["something" "something else"];
|
block = elems.List ["something" "something else"];
|
||||||
};
|
};
|
||||||
asJSON = true;
|
asJSON = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "doesnt match not a list" (let str = "blah blah";
|
(it "doesnt match not a list" (let
|
||||||
|
str = "blah blah";
|
||||||
in {
|
in {
|
||||||
actual = list str;
|
actual = list str;
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -76,11 +76,11 @@ in with md; [
|
||||||
};
|
};
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "processes whole string with all rules" ({
|
(it "processes whole string with all rules" {
|
||||||
actual = processStr ''
|
actual = processStr ''
|
||||||
this text **may** *or may not* contain **bold** words *inside* it.
|
this text **may** *or may not* contain **bold** words *inside* it.
|
||||||
'';
|
'';
|
||||||
expected = (elems.p [
|
expected = elems.p [
|
||||||
"this text"
|
"this text"
|
||||||
(elems.strong "may")
|
(elems.strong "may")
|
||||||
(elems.em "or may not")
|
(elems.em "or may not")
|
||||||
|
@ -89,9 +89,9 @@ in with md; [
|
||||||
"words"
|
"words"
|
||||||
(elems.em "inside")
|
(elems.em "inside")
|
||||||
"it."
|
"it."
|
||||||
]);
|
];
|
||||||
asString = true;
|
asString = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "makes paragraphs" {
|
(it "makes paragraphs" {
|
||||||
actual = readMd ''
|
actual = readMd ''
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
{ it, ... }:
|
{it, ...}: let
|
||||||
let
|
|
||||||
html = import ../nixite/html.nix;
|
html = import ../nixite/html.nix;
|
||||||
elems = import ../nixite/elems.nix;
|
elems = import ../nixite/elems.nix;
|
||||||
site = import ../nixite/site.nix;
|
site = import ../nixite/site.nix;
|
||||||
style = import ../nixite/style.nix;
|
style = import ../nixite/style.nix;
|
||||||
in with site; [
|
in
|
||||||
|
with site; [
|
||||||
(it "applies a style" {
|
(it "applies a style" {
|
||||||
expected = {
|
expected = {
|
||||||
"index.html" = html.tag "html" {} [
|
"index.html" = html.tag "html" {} [
|
||||||
|
@ -27,7 +27,8 @@ in with site; [
|
||||||
this is a stylesheet
|
this is a stylesheet
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
actual = applyStyle ''
|
actual =
|
||||||
|
applyStyle ''
|
||||||
this is a stylesheet
|
this is a stylesheet
|
||||||
'' {
|
'' {
|
||||||
"index.html" = html.tag "html" {} [
|
"index.html" = html.tag "html" {} [
|
||||||
|
@ -182,8 +183,7 @@ in with site; [
|
||||||
in {
|
in {
|
||||||
actual = getLinks {
|
actual = getLinks {
|
||||||
something = "yes";
|
something = "yes";
|
||||||
a-list =
|
a-list = [{thingy = coolPage;} [(elems.img {src = otherPage;} "")]];
|
||||||
[ { thingy = coolPage; } [ (elems.img { src = otherPage; } "") ] ];
|
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
"cool-page" = "cool content";
|
"cool-page" = "cool content";
|
||||||
|
@ -202,7 +202,6 @@ in with site; [
|
||||||
name = "page2";
|
name = "page2";
|
||||||
content = "stuff";
|
content = "stuff";
|
||||||
};
|
};
|
||||||
|
|
||||||
in {
|
in {
|
||||||
actual = extractLinks {
|
actual = extractLinks {
|
||||||
something = "";
|
something = "";
|
||||||
|
@ -220,7 +219,7 @@ in with site; [
|
||||||
};
|
};
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "copies all the files" ({
|
(it "copies all the files" {
|
||||||
actual = copyTo "." {
|
actual = copyTo "." {
|
||||||
page = "this is a page";
|
page = "this is a page";
|
||||||
subdir = {
|
subdir = {
|
||||||
|
@ -235,29 +234,29 @@ in with site; [
|
||||||
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page
|
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page
|
||||||
|
|
||||||
'';
|
'';
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "throws with a list for a page" ({
|
(it "throws with a list for a page" {
|
||||||
actual = copyTo "." {page = [];};
|
actual = copyTo "." {page = [];};
|
||||||
throws = true;
|
throws = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "throws with null for a page" ({
|
(it "throws with null for a page" {
|
||||||
actual = copyTo "." {page = null;};
|
actual = copyTo "." {page = null;};
|
||||||
throws = true;
|
throws = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "throws with a bool for a page" ({
|
(it "throws with a bool for a page" {
|
||||||
actual = copyTo "." {page = true;};
|
actual = copyTo "." {page = true;};
|
||||||
throws = true;
|
throws = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "throws with a number for a page" ({
|
(it "throws with a number for a page" {
|
||||||
actual = copyTo "." {page = 5;};
|
actual = copyTo "." {page = 5;};
|
||||||
throws = true;
|
throws = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
(it "prepares the site" ({
|
(it "prepares the site" {
|
||||||
actual = prepare {favicon = ./src/favicon.png;} {
|
actual = prepare {favicon = ./src/favicon.png;} {
|
||||||
"index.html" = elems.html {} [
|
"index.html" = elems.html {} [
|
||||||
(elems.head {} [(elems.title {} "foobar")])
|
(elems.head {} [(elems.title {} "foobar")])
|
||||||
|
@ -310,6 +309,5 @@ in with site; [
|
||||||
"style.css" = "";
|
"style.css" = "";
|
||||||
};
|
};
|
||||||
asJSON = true;
|
asJSON = true;
|
||||||
}))
|
})
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
{ it, ... }:
|
{it, ...}: let
|
||||||
let
|
|
||||||
style = import ../nixite/style.nix;
|
style = import ../nixite/style.nix;
|
||||||
elems = import ../nixite/elems.nix;
|
elems = import ../nixite/elems.nix;
|
||||||
in [
|
in [
|
||||||
|
(it "fetches empty style" (let
|
||||||
(it "fetches empty style" (let para = (style.component elems.p "para" { });
|
para = style.component elems.p "para" {};
|
||||||
in {
|
in {
|
||||||
expected = {
|
expected = {
|
||||||
"p" = {};
|
"p" = {};
|
||||||
|
@ -15,7 +14,7 @@ in [
|
||||||
|
|
||||||
(it "fetches style" (let
|
(it "fetches style" (let
|
||||||
attrs = {style = {foo = "bar";};};
|
attrs = {style = {foo = "bar";};};
|
||||||
para = (style.component elems.p "para" attrs);
|
para = style.component elems.p "para" attrs;
|
||||||
in {
|
in {
|
||||||
expected = {
|
expected = {
|
||||||
"p" = {};
|
"p" = {};
|
||||||
|
@ -26,7 +25,7 @@ in [
|
||||||
|
|
||||||
(it "appliess class" (let
|
(it "appliess class" (let
|
||||||
attrs = {style = {foo = "bar";};};
|
attrs = {style = {foo = "bar";};};
|
||||||
para = (style.component elems.p "para" attrs);
|
para = style.component elems.p "para" attrs;
|
||||||
in {
|
in {
|
||||||
expected = ["para"];
|
expected = ["para"];
|
||||||
actual = (para "").attrs.class;
|
actual = (para "").attrs.class;
|
||||||
|
@ -37,7 +36,7 @@ in [
|
||||||
style = {foo = "bar";};
|
style = {foo = "bar";};
|
||||||
class = ["other" "class"];
|
class = ["other" "class"];
|
||||||
};
|
};
|
||||||
para = (style.component elems.p "para" attrs);
|
para = style.component elems.p "para" attrs;
|
||||||
in {
|
in {
|
||||||
expected = ["para" "other" "class"];
|
expected = ["para" "other" "class"];
|
||||||
actual = (para "").attrs.class;
|
actual = (para "").attrs.class;
|
||||||
|
@ -45,7 +44,7 @@ in [
|
||||||
|
|
||||||
(it "fetches style for class" (let
|
(it "fetches style for class" (let
|
||||||
s = {foo = "bar";};
|
s = {foo = "bar";};
|
||||||
para = (style.component elems.p "para" { style = s; });
|
para = style.component elems.p "para" {style = s;};
|
||||||
in {
|
in {
|
||||||
expected = {
|
expected = {
|
||||||
"p" = {};
|
"p" = {};
|
||||||
|
@ -61,8 +60,8 @@ in [
|
||||||
"p.para" = {foo = "bar";};
|
"p.para" = {foo = "bar";};
|
||||||
"div.link" = {this = "that";};
|
"div.link" = {this = "that";};
|
||||||
};
|
};
|
||||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
para = style.component elems.p "para" {style = s."p.para";};
|
||||||
div = (style.component elems.div "link" { style = s."div.link"; });
|
div = style.component elems.div "link" {style = s."div.link";};
|
||||||
in {
|
in {
|
||||||
expected = s;
|
expected = s;
|
||||||
actual = style.getStyles (para (div "hello"));
|
actual = style.getStyles (para (div "hello"));
|
||||||
|
@ -76,8 +75,8 @@ in [
|
||||||
"p.para" = {foo = "bar";};
|
"p.para" = {foo = "bar";};
|
||||||
"div.link" = {this = "that";};
|
"div.link" = {this = "that";};
|
||||||
};
|
};
|
||||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
para = style.component elems.p "para" {style = s."p.para";};
|
||||||
a = (style.component elems.div "link" { style = s."div.link"; });
|
a = style.component elems.div "link" {style = s."div.link";};
|
||||||
in {
|
in {
|
||||||
expected = s;
|
expected = s;
|
||||||
actual = style.getStyles (para [(a "hello")]);
|
actual = style.getStyles (para [(a "hello")]);
|
||||||
|
@ -91,8 +90,8 @@ in [
|
||||||
"p.para" = {foo = "bar";};
|
"p.para" = {foo = "bar";};
|
||||||
"div.link" = {this = "that";};
|
"div.link" = {this = "that";};
|
||||||
};
|
};
|
||||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
para = style.component elems.p "para" {style = s."p.para";};
|
||||||
a = (style.component elems.div "link" { style = s."div.link"; });
|
a = style.component elems.div "link" {style = s."div.link";};
|
||||||
in {
|
in {
|
||||||
expected = s;
|
expected = s;
|
||||||
actual = style.getStyles (para [(a "hello") (a "hello")]);
|
actual = style.getStyles (para [(a "hello") (a "hello")]);
|
||||||
|
@ -122,8 +121,8 @@ in [
|
||||||
"p.para" = {foo = "bar";};
|
"p.para" = {foo = "bar";};
|
||||||
"p.oof" = {oof = "yes";};
|
"p.oof" = {oof = "yes";};
|
||||||
};
|
};
|
||||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
para = style.component elems.p "para" {style = s."p.para";};
|
||||||
para2 = (style.component para "oof" { style = s."p.oof"; });
|
para2 = style.component para "oof" {style = s."p.oof";};
|
||||||
in {
|
in {
|
||||||
expected = s;
|
expected = s;
|
||||||
actual = style.getStyles (para2 "");
|
actual = style.getStyles (para2 "");
|
||||||
|
@ -137,11 +136,10 @@ in [
|
||||||
"p.para" = {foo = "bar";};
|
"p.para" = {foo = "bar";};
|
||||||
"p.para.oof" = {oof = "yes";};
|
"p.para.oof" = {oof = "yes";};
|
||||||
};
|
};
|
||||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
para = style.component elems.p "para" {style = s."p.para";};
|
||||||
para2 = (style.component para "oof" { style = s."p.para.oof"; });
|
para2 = style.component para "oof" {style = s."p.para.oof";};
|
||||||
in {
|
in {
|
||||||
expected = ["para" "oof"];
|
expected = ["para" "oof"];
|
||||||
actual = (para2 "").attrs.class;
|
actual = (para2 "").attrs.class;
|
||||||
}))
|
}))
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue