about summary refs log tree commit diff
path: root/users/grfn/gws.fyi/orgExportHTML.nix
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-08-18T02·16-0400
committergrfn <grfn@gws.fyi>2021-08-18T03·22+0000
commit8dd5ee26d737b1ea62c607480d4f1e1c2d9d2f73 (patch)
tree80c2f66b4dda56b1cee0e34c0909d3650e091f3f /users/grfn/gws.fyi/orgExportHTML.nix
parentdb3fdd5ee865a292a711fdcc788943bee4fda8a2 (diff)
feat(gws.fyi): Allow building whole org directories r/2747
Allow building entire directories containing org files as html
directories with org-export-html

Change-Id: I805da6b2da7e8ea67da13c858f962f36ed120972
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3370
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to '')
-rw-r--r--users/grfn/gws.fyi/orgExportHTML.nix50
1 files changed, 37 insertions, 13 deletions
diff --git a/users/grfn/gws.fyi/orgExportHTML.nix b/users/grfn/gws.fyi/orgExportHTML.nix
index ad5a247958..e918e697d9 100644
--- a/users/grfn/gws.fyi/orgExportHTML.nix
+++ b/users/grfn/gws.fyi/orgExportHTML.nix
@@ -22,12 +22,23 @@ let
   bn = builtins.baseNameOf src;
   filename = elemAt (splitString "." bn) 0;
 
+  isDirectory = import (runCommand "isDirectory" {} ''
+    if [ -d ${src} ]; then
+      echo "true" > $out
+    else
+      echo "false" > $out
+    fi
+  '');
+
   outName =
     if isNull headline
     then
       let bn = builtins.baseNameOf src;
           filename = elemAt (splitString "." bn) 0;
-      in filename + ".html"
+      in
+        if isDirectory
+        then filename
+        else filename + ".html"
     else "${filename}-${replaceStrings [" "] ["-"] filename}.html";
 
   escapeDoubleQuotes = replaceStrings ["\""] ["\\\""];
@@ -39,16 +50,29 @@ let
 
 in
 
-runCommand outName {} ''
-  cp ${src} file.org
-  echo "${emacs}/bin/emacs --batch"
-  ${emacs}/bin/emacs --batch \
-    --load ${./config.el} \
-    --visit file.org \
-    --eval "(progn
-      ${escapeDoubleQuotes navToHeadline}
-      (org-html-export-to-html))" \
-    --kill
-  substitute file.html $out \
-    --replace '<title>&lrm;</title>' ""
+runCommand outName { inherit src; } ''
+  buildFile() {
+    cp "$1" file.org
+    ${emacs}/bin/emacs --batch \
+      --load ${./config.el} \
+      --visit file.org \
+      --eval "(progn
+        ${escapeDoubleQuotes navToHeadline}
+        (org-html-export-to-html))" \
+      --kill
+    rm file.org
+    substitute file.html "$2" \
+      --replace '<title>&lrm;</title>' ""
+    rm file.html
+  }
+
+  if [ -d $src ]; then
+    for file in $src/*; do
+      result=''${file/$src/$out}
+      mkdir -p $(dirname $result)
+      buildFile $file ''${result/.org/.html}
+    done
+  else
+    buildFile $src $out
+  fi
 ''