From 8dd5ee26d737b1ea62c607480d4f1e1c2d9d2f73 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Tue, 17 Aug 2021 22:16:56 -0400 Subject: feat(gws.fyi): Allow building whole org directories 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 --- users/grfn/gws.fyi/orgExportHTML.nix | 50 ++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-) (limited to 'users/grfn/gws.fyi') diff --git a/users/grfn/gws.fyi/orgExportHTML.nix b/users/grfn/gws.fyi/orgExportHTML.nix index ad5a24795826..e918e697d973 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 '' "" +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 '' "" + 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 '' -- cgit 1.4.1