2021-08-18 11:38:59 +02:00
|
|
|
{ pkgs, depot, ... }:
|
2020-06-16 04:24:13 +02:00
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2022-05-04 15:15:16 +02:00
|
|
|
emacs = pkgs.emacs28;
|
2020-06-16 04:24:13 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
|
2020-06-16 05:18:17 +02:00
|
|
|
opts:
|
2020-06-16 04:24:13 +02:00
|
|
|
|
|
|
|
let
|
2020-06-16 05:18:17 +02:00
|
|
|
src = if isAttrs opts then opts.src else opts;
|
|
|
|
headline = if isAttrs opts then opts.headline else null;
|
|
|
|
|
|
|
|
bn = builtins.baseNameOf src;
|
|
|
|
filename = elemAt (splitString "." bn) 0;
|
2020-06-16 04:24:13 +02:00
|
|
|
|
|
|
|
outName =
|
2020-06-16 05:18:17 +02:00
|
|
|
if isNull headline
|
|
|
|
then
|
|
|
|
let
|
|
|
|
bn = builtins.baseNameOf src;
|
|
|
|
filename = elemAt (splitString "." bn) 0;
|
2021-08-18 04:16:56 +02:00
|
|
|
in
|
2021-08-18 11:38:59 +02:00
|
|
|
if depot.nix.utils.isDirectory src
|
2021-08-18 04:16:56 +02:00
|
|
|
then filename
|
|
|
|
else filename + ".html"
|
2020-06-16 05:18:17 +02:00
|
|
|
else "${filename}-${replaceStrings [" "] ["-"] filename}.html";
|
|
|
|
|
|
|
|
escapeDoubleQuotes = replaceStrings [ "\"" ] [ "\\\"" ];
|
|
|
|
|
|
|
|
navToHeadline = optionalString (! isNull headline) ''
|
|
|
|
(search-forward "${escapeDoubleQuotes headline}")
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
'';
|
2020-06-16 04:24:13 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
|
2021-08-18 04:16:56 +02:00
|
|
|
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" \
|
2024-08-08 05:15:27 +02:00
|
|
|
--replace-quiet '<title>‎</title>' ""
|
2021-08-18 04:16:56 +02:00
|
|
|
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
|
2020-06-16 04:24:13 +02:00
|
|
|
''
|