2024-11-13 15:24:41 +01:00
|
|
|
{ config, options, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
mkOption
|
|
|
|
types
|
|
|
|
;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
config.templates.html = {
|
2024-11-13 15:24:41 +01:00
|
|
|
dom = document:
|
|
|
|
let
|
|
|
|
eval = lib.evalModules {
|
|
|
|
class = "DOM";
|
|
|
|
modules = [ document (import ./dom.nix) ];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
__toString = _: toString eval.config;
|
|
|
|
value = eval.config;
|
|
|
|
};
|
|
|
|
|
2024-11-13 15:24:41 +01:00
|
|
|
markdown = { name, body }:
|
|
|
|
let
|
|
|
|
commonmark = pkgs.runCommand "${name}.html"
|
|
|
|
{
|
|
|
|
buildInputs = [ pkgs.cmark ];
|
|
|
|
} ''
|
|
|
|
cmark ${builtins.toFile "${name}.md" body} > $out
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
builtins.readFile commonmark;
|
|
|
|
nav = { menu, page }:
|
|
|
|
let
|
|
|
|
render-item = item:
|
|
|
|
if item ? menu then ''
|
2024-11-13 15:24:41 +01:00
|
|
|
<li><details><summary>${item.menu.label}</summary>
|
2024-11-13 15:24:41 +01:00
|
|
|
${lib.indent " " (item.menu.outputs.html page)}
|
|
|
|
</li>
|
|
|
|
''
|
|
|
|
else if item ? page then ''<li><a href="${page.link item.page}">${item.page.title}</a></li>''
|
|
|
|
else ''<li><a href="${item.link.url}">${item.link.label}</a></li>''
|
|
|
|
;
|
|
|
|
in
|
|
|
|
''
|
|
|
|
<nav>
|
|
|
|
<ul>
|
|
|
|
${with lib; indent " " (join "\n" (map render-item menu.items))}
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
'';
|
|
|
|
};
|
2024-11-13 15:24:41 +01:00
|
|
|
|
|
|
|
config.templates.files = fs: with lib;
|
|
|
|
foldl'
|
|
|
|
# TODO: create static redirects from `tail <collection>.locations`
|
|
|
|
(acc: elem: acc // (mapAttrs' (type: value: {
|
|
|
|
name = head elem.locations + optionalString (type != "") ".${type}";
|
2024-11-13 15:24:41 +01:00
|
|
|
value = if isStorePath value then value else
|
|
|
|
builtins.toFile
|
2024-11-13 15:24:41 +01:00
|
|
|
(elem.name + optionalString (type != "") ".${type}")
|
|
|
|
(toString value);
|
|
|
|
}))
|
|
|
|
elem.outputs)
|
|
|
|
{ }
|
|
|
|
fs;
|
2024-11-13 15:24:41 +01:00
|
|
|
}
|