diff --git a/website/presentation/default.nix b/website/presentation/default.nix
index 4448fcb6..0d3eb285 100644
--- a/website/presentation/default.nix
+++ b/website/presentation/default.nix
@@ -21,6 +21,9 @@ in
Each template function takes the complete site `config` and the document's data structure.
'';
+ # TODO: this function should probably take a single attrs,
+ # otherwise it's quite inflexible.
+ # named parameters would also help with readability at the call site
type = recursiveAttrs (with types; functionTo (functionTo str));
};
@@ -34,6 +37,7 @@ in
'';
in
{
+ nav = lib.mkDefault templates.nav;
page = lib.mkDefault (config: page: templates.html {
head = ''
${page.title}
@@ -41,7 +45,7 @@ in
'';
body = ''
- ${templates.nav { inherit page; menu = { menu = config.menus.main; }; }}
+ ${config.menus.main.outputs.html page}
${builtins.readFile (commonmark page.name page.body)}
'';
});
@@ -55,7 +59,7 @@ in
}
'';
body = ''
- ${templates.nav { inherit page; menu = { menu = config.menus.main; }; }}
+ ${config.menus.main.outputs.html page}
${builtins.readFile (commonmark page.name page.body)}
'';
});
diff --git a/website/presentation/templates.nix b/website/presentation/templates.nix
index f4567aa6..d33630b1 100644
--- a/website/presentation/templates.nix
+++ b/website/presentation/templates.nix
@@ -14,17 +14,16 @@ rec {
'';
- nav = { page, menu }:
+ nav = menu: page:
let
render-item = item:
- if item ? menu then
- ''
-
${item.menu.label}
- ${lib.indent " " (nav { inherit page; menu = item; })}
- ''
- else
- if item ? page then ''
''
;
in
''
diff --git a/website/structure/navigation.nix b/website/structure/navigation.nix
index 12670278..a3d78360 100644
--- a/website/structure/navigation.nix
+++ b/website/structure/navigation.nix
@@ -29,7 +29,7 @@ in
};
};
- content-types.navigation = { name, ... }: {
+ content-types.navigation = { name, config, ... }: {
options = {
name = mkOption {
description = "Symbolic name, used as a human-readable identifier";
@@ -49,6 +49,15 @@ in
link = mkOption { type = submodule cfg.content-types.named-link; };
});
};
+ outputs = mkOption {
+ description = ''
+ Representations of the navigation structure in different formats
+
+ It must be a function that takes the page on which the navigation is to be shown, such that relative links get computed correctly.
+ '';
+ type = with types; attrsOf (functionTo str);
+ default.html = cfg.templates.html.nav { menu = config; };
+ };
};
};
}