From 1a8b04f21a021652b1704a7d06c758ddac5df417 Mon Sep 17 00:00:00 2001
From: valentin gagarin <valentin.gagarin@tweag.io>
Date: Wed, 13 Nov 2024 15:24:40 +0100
Subject: [PATCH] extract file processing

---
 lib.nix | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/lib.nix b/lib.nix
index c3d6fbdb..6b8053e1 100644
--- a/lib.nix
+++ b/lib.nix
@@ -23,17 +23,24 @@ rec {
       cmark ${builtins.toFile "${name}.md" markdown} > $out
     '';
 
-  files = dir: lib.mapAttrs'
+  /**
+    Get documents from a flat directory of files
+  */
+  documents = dir: lib.mapAttrs'
     (
-      attrname: value:
-        let
-          document = import (dir + "/${attrname}");
-          name = lib.removeSuffix ".nix" attrname;
-        in
-        {
-          name = "${name}.html";
-          value = html document "${name}.html";
-        }
+      attrname: value: {
+        name = lib.removeSuffix ".nix" attrname;
+        value = import (dir + "/${attrname}");
+      }
     )
     (builtins.readDir dir);
+
+  files = dir: lib.mapAttrs'
+    (
+      name: document: {
+        name = document.outPath;
+        value = html document "${name}.html";
+      }
+    )
+    (documents dir);
 }