From 0fbcedbd1a7244dafd7596d07c6a85f07ec9f2f1 Mon Sep 17 00:00:00 2001 From: valentin gagarin Date: Wed, 13 Nov 2024 15:24:40 +0100 Subject: [PATCH] extract main document conversion --- website/lib.nix | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/website/lib.nix b/website/lib.nix index 7e8e1b1..c3d6fbd 100644 --- a/website/lib.nix +++ b/website/lib.nix @@ -1,17 +1,38 @@ { pkgs, lib, ... }: -{ +rec { + /** + Convert a Nix document to HTML + */ + html = document: name: + builtins.toFile "${name}.html" '' + + + ${document.title} + + + ${builtins.readFile (commonmark document.body name)} + + + ''; + + /** + 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);