diff --git a/flake.nix b/flake.nix
index 44f5587..179b364 100644
--- a/flake.nix
+++ b/flake.nix
@@ -20,10 +20,10 @@
"index.html" = with nixite.elems; (doc [
[
(title "Nixite")
+ (nixite.html.tag "link" {rel = "shortcut icon"; type = "image/png"; href = ./testing/src/favicon.png;} "")
]
(main [
(link "/blog" "blog")
- (nixite.html.tag "img" {src = ./testing/src/favicon.png;} "")
(list [
"item 1"
"item 2"
@@ -31,19 +31,7 @@
])
])
]);
- blog = {
- "index.html" = with nixite.elems; (doc [
- [
- (title "A post")
- ]
- (main [
- (p ''
- This is a post
- '')
- (link "/" "Home")
- ])
- ]);
- };
+ blog = nixite.md.readDir ./testing/blog;
})
);
diff --git a/nixite/md.nix b/nixite/md.nix
index 70dda06..3055c30 100644
--- a/nixite/md.nix
+++ b/nixite/md.nix
@@ -5,11 +5,46 @@ in rec {
if builtins.isPath md
then processMd (builtins.readFile md)
else processMd md;
+
processMd = md: (map (c:
if builtins.isString c
then mdBlock c
else "") (builtins.split "\n\n" md));
+ recReadMd = root:
+ assert builtins.isPath root;
+ builtins.mapAttrs
+ (path: type:
+ if type == "directory"
+ then recReadMd (root + (/. + path))
+ else if type == "regular"
+ then mdToPage (root + (/. + path))
+ else throw "Cannot read ${path}, file type ${type}")
+ (builtins.readDir root);
+
+ recFixAppendix = site:
+ builtins.listToAttrs (
+ builtins.attrValues (
+ builtins.mapAttrs (name: value: {
+ name = fixAppendix name;
+ value =
+ if builtins.isAttrs value
+ then recFixAppendix value
+ else value;
+ })
+ site
+ )
+ );
+
+ fixAppendix = builtins.replaceStrings [".md"] [".html"];
+
+ readDir = root: recFixAppendix (recReadMd root);
+
+ mdToPage = md: elems.doc [
+ [(elems.title "markdown file")]
+ (readMd md)
+ ];
+
mdBlock = block: let
m = heading block;
h =
diff --git a/nixite/site.nix b/nixite/site.nix
index 50bec05..d0719a0 100644
--- a/nixite/site.nix
+++ b/nixite/site.nix
@@ -69,7 +69,7 @@ in rec {
mkdir -p ${prefix}/${name}
${copyTo "${prefix}/${name}" content}
''
- else throw "Site page must be string, path or attrset"
+ else throw "Site page must be string, path or attrset, but got ${builtins.typeOf content}: [${toString content}]"
)
site
)
diff --git a/testing/blog/dir/index.md b/testing/blog/dir/index.md
new file mode 100644
index 0000000..719951f
--- /dev/null
+++ b/testing/blog/dir/index.md
@@ -0,0 +1,3 @@
+# this is a file
+
+wowo
diff --git a/testing/blog/index.md b/testing/blog/index.md
new file mode 100644
index 0000000..45e6fa5
--- /dev/null
+++ b/testing/blog/index.md
@@ -0,0 +1,9 @@
+# yeee
+
+ye
+
+&
+
+dir
+home
+
diff --git a/testing/md.test.nix b/testing/md.test.nix
index b2afc46..0d92175 100644
--- a/testing/md.test.nix
+++ b/testing/md.test.nix
@@ -24,4 +24,44 @@ in
(elems.p {} "lorem ipsum\n")
];
})
+
+ (it "can fix file appendixes" {
+ actual = fixAppendix "index.md";
+ expected = "index.html";
+ })
+
+ (it "recursively reads dir" {
+ actual = recReadMd ./blog;
+ expected = {
+ "index.md" = mdToPage ./blog/index.md;
+ "dir" = {
+ "index.md" = mdToPage ./blog/dir/index.md;
+ };
+ };
+ })
+
+ (it "recursively fixes filename" {
+ actual = recFixAppendix {
+ "index.md" = "something";
+ dir = {
+ "index.md" = "something else";
+ };
+ };
+ expected = {
+ "index.html" = "something";
+ dir = {
+ "index.html" = "something else";
+ };
+ };
+ })
+
+ (it "recursively translates md to html" {
+ actual = builtins.toJSON ( readDir ./blog );
+ expected = builtins.toJSON {
+ "index.html" = mdToPage ./blog/index.md;
+ "dir" = {
+ "index.html" = mdToPage ./blog/dir/index.md;
+ };
+ };
+ })
]