This repository has been archived on 2024-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
fediversity.eu/lib.nix

47 lines
985 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
/**
Get documents from a flat directory of files
*/
documents = dir: lib.mapAttrs'
2024-11-13 15:24:40 +01:00
(
2024-11-13 15:24:40 +01:00
attrname: value: {
name = lib.removeSuffix ".nix" attrname;
value = import (dir + "/${attrname}");
}
2024-11-13 15:24:40 +01:00
)
(builtins.readDir dir);
2024-11-13 15:24:40 +01:00
files = dir: lib.mapAttrs'
(
name: document: {
name = document.outPath;
value = html document "${name}.html";
}
)
(documents dir);
2024-11-13 15:24:40 +01:00
}