Fediversity/website/lib.nix

40 lines
868 B
Nix
Raw Normal View History

2024-11-13 15:24:40 +01:00
{ pkgs, lib, ... }:
2024-11-13 15:24:40 +01:00
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
'';
2024-11-13 15:24:40 +01:00
files = dir: lib.mapAttrs'
(
2024-11-13 15:24:40 +01:00
attrname: value:
2024-11-13 15:24:40 +01:00
let
2024-11-13 15:24:40 +01:00
document = import (dir + "/${attrname}");
name = lib.removeSuffix ".nix" attrname;
2024-11-13 15:24:40 +01:00
in
{
2024-11-13 15:24:40 +01:00
name = "${name}.html";
value = html document "${name}.html";
2024-11-13 15:24:40 +01:00
}
)
(builtins.readDir dir);
}