2021-08-18 11:38:59 +02:00
|
|
|
{ pkgs, depot, ... }:
|
2020-06-16 04:24:13 +02:00
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2020-08-28 16:25:10 +02:00
|
|
|
emacsWithPackages = (pkgs.emacsPackagesGen pkgs.emacs27).emacsWithPackages;
|
|
|
|
|
|
|
|
emacs = emacsWithPackages (p: with p; [
|
|
|
|
org
|
|
|
|
]);
|
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" \
|
|
|
|
--replace '<title>‎</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
|
2020-06-16 04:24:13 +02:00
|
|
|
''
|