2024-11-13 15:24:40 +01:00
|
|
|
{ pkgs, lib, ... }:
|
2024-11-13 15:24:40 +01:00
|
|
|
let
|
|
|
|
join = lib.concatStringsSep;
|
|
|
|
in
|
2024-11-13 15:24:40 +01:00
|
|
|
rec {
|
2024-11-13 15:24:40 +01:00
|
|
|
/**
|
|
|
|
Build the web site
|
|
|
|
*/
|
2024-11-13 15:24:40 +01:00
|
|
|
build = name: dir:
|
2024-11-13 15:24:40 +01:00
|
|
|
let
|
|
|
|
script = ''
|
|
|
|
mkdir $out
|
|
|
|
'' + join "\n" copy;
|
|
|
|
copy = lib.mapAttrsToList
|
|
|
|
(
|
|
|
|
path: document: ''
|
|
|
|
mkdir -p $out/$(dirname ${path})
|
|
|
|
cp ${document} $out/${path}
|
|
|
|
''
|
|
|
|
)
|
|
|
|
(files (sources dir));
|
|
|
|
in
|
|
|
|
pkgs.runCommand name { } script;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get source files from a flat directory
|
|
|
|
*/
|
|
|
|
sources = dir: lib.mapAttrs'
|
|
|
|
(
|
|
|
|
attrname: value: {
|
|
|
|
name = lib.removeSuffix ".nix" attrname;
|
|
|
|
value = import (dir + "/${attrname}");
|
|
|
|
}
|
|
|
|
)
|
|
|
|
(builtins.readDir dir);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a mapping from output file path to document contents
|
|
|
|
*/
|
|
|
|
files = documents: lib.mapAttrs'
|
|
|
|
(
|
|
|
|
name: document: {
|
|
|
|
name = document.outPath;
|
|
|
|
value = html document "${name}.html";
|
|
|
|
}
|
|
|
|
)
|
|
|
|
documents;
|
|
|
|
|
2024-11-13 15:24:40 +01:00
|
|
|
/**
|
|
|
|
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
|
|
|
}
|