Compare commits

...

2 commits

Author SHA1 Message Date
Valentin Gagarin c5fad394de fix semantics: wrap content body into section 2024-11-08 15:15:45 +01:00
Valentin Gagarin 15984affec make template overrides chainable 2024-11-07 17:55:23 +01:00
4 changed files with 45 additions and 10 deletions

View file

@ -36,6 +36,15 @@ rec {
packages = with pkgs; [ packages = with pkgs; [
cmark cmark
npins npins
watchexec
]; ];
shellHook = ''
cat << EOF
For incremental rebuilds:
echo watchexec -e nix "nix-build -A build"
firefox --new-tab file:///${toString ./.}/result/index.html
EOF
'';
}; };
} }

17
lib.nix
View file

@ -1,7 +1,22 @@
{ lib }: { lib }:
rec { rec {
template = g: f: x: template = g: f: x:
(g (f x)) // { override = o: g (lib.recursiveUpdate (f x) o); }; let
base = f x;
result = g base;
in
result // {
override = new:
let
# TODO: let overrides take the previous state as an argument
# base' = lib.recursiveUpdate base (new base);
base' = lib.recursiveUpdate base new;
result' = g base';
in
result' // {
override = new: (template g (x': base') x).override new;
};
};
/** /**
Recursively replace occurrences of `from` with `to` within `string` Recursively replace occurrences of `from` with `to` within `string`

View file

@ -31,18 +31,23 @@ in
html = { html = {
# TODO: make authors always a list # TODO: make authors always a list
head.meta.authors = if lib.isList config.author then config.author else [ config.author ]; head.meta.authors = if lib.isList config.author then config.author else [ config.author ];
head.title.text = lib.mkForce "yeah";
body.content = lib.mkForce [ body.content = lib.mkForce [
(cfg.menus.main.outputs.html config) (cfg.menus.main.outputs.html config)
{ {
section.heading = { section = {
# TODO: i18n support heading = {
# TODO: structured dates # TODO: i18n support
before = [{ p.content = "Published ${config.date}"; }]; # TODO: structured dates
content = config.title; before = [{ p.content = "Published ${config.date}"; }];
after = [{ p.content = "Written by ${config.author}"; }]; content = config.title;
after = [{ p.content = "Written by ${config.author}"; }];
};
content = [
(cfg.templates.html.markdown { inherit (config) name body; })
];
}; };
} }
(cfg.templates.html.markdown { inherit (config) name body; })
]; ];
}; };
}); });

View file

@ -64,8 +64,14 @@ in
}; };
body.content = [ body.content = [
(cfg.menus.main.outputs.html page) (cfg.menus.main.outputs.html page)
{ section.heading.content = page.title; } {
(cfg.templates.html.markdown { inherit (page) name body; }) section = {
heading.content = page.title;
content = [
(cfg.templates.html.markdown { inherit (page) name body; })
];
};
}
]; ];
}; };
}); });