2021-08-18 11:38:59 +02:00
|
|
|
{ pkgs, depot, ... }:
|
2020-06-16 04:24:13 +02:00
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
with lib;
|
|
|
|
|
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;
|
2024-10-03 21:24:30 +02:00
|
|
|
configFile = opts.configFile or ./config.el;
|
2020-06-16 05:18:17 +02:00
|
|
|
|
|
|
|
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
|
2022-01-30 17:06:58 +01:00
|
|
|
let
|
|
|
|
bn = builtins.baseNameOf src;
|
|
|
|
filename = elemAt (splitString "." bn) 0;
|
2021-08-18 04:16:56 +02:00
|
|
|
in
|
2022-01-30 17:06:58 +01:00
|
|
|
if depot.nix.utils.isDirectory src
|
|
|
|
then filename
|
|
|
|
else filename + ".html"
|
2020-06-16 05:18:17 +02:00
|
|
|
else "${filename}-${replaceStrings [" "] ["-"] filename}.html";
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
escapeDoubleQuotes = replaceStrings [ "\"" ] [ "\\\"" ];
|
2020-06-16 05:18:17 +02:00
|
|
|
|
|
|
|
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
|
2024-10-03 20:54:44 +02:00
|
|
|
${pkgs.emacs}/bin/emacs --batch \
|
2024-10-03 21:24:30 +02:00
|
|
|
--load ${configFile} \
|
2021-08-18 04:16:56 +02:00
|
|
|
--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
|
|
|
''
|