Fediversity/website/structure/event.nix

97 lines
2.9 KiB
Nix
Raw Permalink Normal View History

2025-02-19 18:34:19 +01:00
{
config,
options,
lib,
...
}:
2024-11-13 15:24:41 +01:00
let
inherit (lib)
mkOption
types
;
cfg = config;
in
{
2025-02-19 18:34:19 +01:00
content-types.event =
{ config, collection, ... }:
{
imports = [ cfg.content-types.page ];
options = {
collection = mkOption {
description = "Collection this event belongs to";
type = options.collections.type.nestedTypes.elemType;
default = collection;
};
start-date = mkOption {
description = "Start date of the event";
type = with types; str;
};
start-time = mkOption {
description = "Start time of the event";
type = with types; str;
default = null;
};
end-date = mkOption {
description = "End date of the event";
type = with types; str;
default = null;
};
end-time = mkOption {
description = "End time of the event";
type = with types; str;
default = null;
};
location = mkOption {
description = "Location of the event";
type = with types; str;
};
2024-11-13 15:24:41 +01:00
};
2025-02-19 18:34:19 +01:00
config.name = with lib; mkDefault (slug config.title);
config.summary = lib.mkDefault config.description;
config.outputs.html = lib.mkForce (
(cfg.templates.html.page config).override (
2025-02-19 18:38:05 +01:00
_final: prev: {
2025-02-19 18:34:19 +01:00
html.body.content =
with lib;
map (
e:
if isAttrs e && e ? section then
recursiveUpdate e {
section.content = [
{
dl.content =
[
{
terms = [ { dt = "Location"; } ];
descriptions = [ { dd = config.location; } ];
}
{
terms = [ { dt = "Start"; } ];
descriptions = [
{
dd = config.start-date + lib.optionalString (!isNull config.start-time) " ${config.start-time}";
}
];
}
]
++ lib.optional (!isNull config.end-date) {
terms = [ { dt = "End"; } ];
descriptions = [
{
dd = config.end-date + lib.optionalString (!isNull config.end-time) " ${config.end-time}";
}
];
};
}
] ++ e.section.content;
}
else
e
) prev.html.body.content;
2024-11-13 15:24:41 +01:00
2025-02-19 18:34:19 +01:00
}
)
);
};
2024-11-13 15:24:41 +01:00
}