From d2265cb2b7c8f4f62ba2b57aec817c7bf9a7e919 Mon Sep 17 00:00:00 2001 From: valentin gagarin Date: Wed, 13 Nov 2024 15:24:41 +0100 Subject: [PATCH] allow menu entries to be subtypes of `page` with an example --- content/navigation.nix | 16 +++++++++++++++- structure/navigation.nix | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/content/navigation.nix b/content/navigation.nix index e7eb7dad..f7577621 100644 --- a/content/navigation.nix +++ b/content/navigation.nix @@ -1,4 +1,4 @@ -{ config, ... }: +{ config, lib, ... }: let inherit (config) pages; in @@ -10,6 +10,20 @@ in menu.label = "Consortium"; menu.items = map (page: { inherit page; }) (with pages; [ nlnet oid tweag nordunet ]); } + { + menu.label = "News"; + menu.items = + let + sorted = with lib; reverseList (sortOn (entry: entry.date) config.collections.news.entry); + in + map + (page: { + page = lib.recursiveUpdate page { + title = "${page.date}: ${page.title}"; + }; + }) + (lib.take 3 sorted); + } { page = pages.fediversity; } { page = pages.grants; } ]; diff --git a/structure/navigation.nix b/structure/navigation.nix index a642bcaa..17bae29f 100644 --- a/structure/navigation.nix +++ b/structure/navigation.nix @@ -5,6 +5,10 @@ let types ; cfg = config; + subtype = baseModule: types.submodule [ + baseModule + { _module.freeformType = types.attrs; } + ]; in { content-types.named-link = { ... }: { @@ -36,7 +40,7 @@ in 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; }; + page = mkOption { type = subtype cfg.content-types.page; }; link = mkOption { type = submodule cfg.content-types.named-link; }; }); };