From 2e2bf6307b773ff0ea3dc4cd16bbbf670ccafdc5 Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 14 Oct 2024 13:52:52 +0200 Subject: [PATCH] implement navigation --- content/navigation.nix | 21 ++++++++++++++++++++ presentation/default.nix | 10 ++++++++-- presentation/templates.nix | 22 ++++++++++++++++++++- structure/content-types.nix | 38 ++++++++++++++++++++++++++++++++++++- structure/default.nix | 6 ++++++ 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 content/navigation.nix diff --git a/content/navigation.nix b/content/navigation.nix new file mode 100644 index 0000000..f62263e --- /dev/null +++ b/content/navigation.nix @@ -0,0 +1,21 @@ +{ config, ... }: +let + inherit (config) pages; +in +{ + menus.main = { + label = "Main"; + items = [ + { + menu.label = "Consortium"; + menu.items = map (page: { inherit page; }) (with pages; [ nlnet oid tweag nordunet ]); + } + { + page = pages.fediversity; + } + { + page = pages.grants; + } + ]; + }; +} diff --git a/presentation/default.nix b/presentation/default.nix index ca49c9a..d3f3ef6 100644 --- a/presentation/default.nix +++ b/presentation/default.nix @@ -37,7 +37,10 @@ in ''; - body = builtins.readFile (commonmark page.name page.body); + body = '' + ${templates.nav { menu = { menu = config.menus.main; }; }} + ${builtins.readFile (commonmark page.name page.body)} + ''; }); }); article = lib.mkDefault (config: page: { @@ -48,7 +51,10 @@ in ''; - body = builtins.readFile (commonmark page.name page.body); + body = '' + ${templates.nav { menu = { menu = config.menus.main; }; }} + ${builtins.readFile (commonmark page.name page.body)} + ''; }); }); }; diff --git a/presentation/templates.nix b/presentation/templates.nix index 2de9d10..f412442 100644 --- a/presentation/templates.nix +++ b/presentation/templates.nix @@ -1,5 +1,5 @@ { lib }: -{ +rec { html = { head, body }: '' @@ -14,4 +14,24 @@ ''; + nav = { menu }: + let + render-item = item: + if item ? menu then + '' +
  • ${item.menu.label} + ${lib.indent " " (nav { menu = item; })} + '' + else + if item ? page then ''
  • ${item.page.title}
  • '' + else ''
  • ${item.link.label}
  • '' + ; + in + '' + + ''; } diff --git a/structure/content-types.nix b/structure/content-types.nix index 22b0796..7ff4215 100644 --- a/structure/content-types.nix +++ b/structure/content-types.nix @@ -17,7 +17,7 @@ in page = { name, config, ... }: { options = { name = mkOption { - description = "Symbolic name for the page, used as a human-readable identifier"; + description = "Symbolic name, used as a human-readable identifier"; type = types.str; default = name; }; @@ -93,5 +93,41 @@ in config.outPath = "${collectionName}/${lib.head config.locations}"; config.template = cfg.templates.article; }; + + named-link = { ... }: { + options = { + label = mkOption { + description = "Link label"; + type = types.str; + }; + url = mkOption { + description = "Link URL"; + type = types.str; + }; + }; + }; + + navigation = { name, ... }: { + options = { + name = mkOption { + description = "Symbolic name, used as a human-readable identifier"; + type = types.str; + default = name; + }; + label = mkOption { + description = "Menu label"; + type = types.str; + default = name; + }; + items = mkOption { + description = "List of menu items"; + type = with types; listOf (attrTag { + menu = mkOption { type = submodule cfg.content-types.navigation; }; + page = mkOption { type = submodule cfg.content-types.page; }; + link = mkOption { type = submodule cfg.content-types.named-link; }; + }); + }; + }; + }; }; } diff --git a/structure/default.nix b/structure/default.nix index 01148eb..df80b94 100644 --- a/structure/default.nix +++ b/structure/default.nix @@ -54,4 +54,10 @@ in })); }; + options.menus = mkOption { + description = '' + Collection navigation menus + ''; + type = with types; attrsOf (submodule config.content-types.navigation); + }; }