extract main document conversion

This commit is contained in:
Valentin Gagarin 2024-10-11 12:50:31 +02:00
parent 2bb88dff9b
commit 5b81645f57

37
lib.nix
View file

@ -1,17 +1,38 @@
{ pkgs, lib, ... }:
{
rec {
/**
Convert a Nix document to HTML
*/
html = document: name:
builtins.toFile "${name}.html" ''
<html>
<head>
<title>${document.title}</title>
</head>
<body>
${builtins.readFile (commonmark document.body name)}
<body>
</html>
'';
/**
Convert a commonmark string to HTML
*/
commonmark = markdown: name:
pkgs.runCommand "${name}.html" { buildInputs = [ pkgs.cmark ]; } ''
cmark ${builtins.toFile "${name}.md" markdown} > $out
'';
files = dir: lib.mapAttrs'
(
name: value:
attrname: value:
let
html = "${lib.removeSuffix ".nix" name}.html";
md = "${lib.removeSuffix ".nix" name}.md";
document = import (dir + "/${attrname}");
name = lib.removeSuffix ".nix" attrname;
in
{
name = html;
value = pkgs.runCommand html { buildInputs = with pkgs; [ cmark ]; } ''
cmark ${builtins.toFile md (import (dir + "/${name}")).body} > $out
'';
name = "${name}.html";
value = html document "${name}.html";
}
)
(builtins.readDir dir);