2024-11-13 15:24:41 +01:00
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
mkOption
|
|
|
|
types
|
|
|
|
;
|
|
|
|
cfg = config;
|
|
|
|
in
|
|
|
|
{
|
2024-11-13 15:24:41 +01:00
|
|
|
# TODO: enable i18n, e.g. via a nested attribute for language-specific content
|
|
|
|
options.pages = mkOption {
|
|
|
|
description = ''
|
|
|
|
Collection of pages on the site
|
|
|
|
'';
|
|
|
|
type = with types; attrsOf (submodule config.content-types.page);
|
|
|
|
};
|
2024-11-13 15:24:41 +01:00
|
|
|
|
|
|
|
config.files = with lib; cfg.templates.files (attrValues config.pages);
|
2024-11-13 15:24:41 +01:00
|
|
|
|
|
|
|
config.content-types.page = { name, config, ... }: {
|
2024-11-13 15:24:41 +01:00
|
|
|
imports = [ cfg.content-types.document ];
|
|
|
|
options = {
|
|
|
|
title = mkOption {
|
|
|
|
description = "Page title";
|
|
|
|
type = types.str;
|
|
|
|
default = name;
|
|
|
|
};
|
|
|
|
description = mkOption {
|
|
|
|
description = ''
|
|
|
|
One-sentence description of page contents
|
|
|
|
'';
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
summary = mkOption {
|
|
|
|
description = ''
|
|
|
|
One-paragraph summary of page contents
|
|
|
|
'';
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
body = mkOption {
|
|
|
|
description = ''
|
|
|
|
Page contents in CommonMark
|
|
|
|
'';
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
2024-11-13 15:24:41 +01:00
|
|
|
|
|
|
|
config.outputs.html = cfg.templates.html.page config;
|
|
|
|
};
|
|
|
|
|
|
|
|
config.templates.html.page = lib.template cfg.templates.html.dom (page: {
|
|
|
|
html = {
|
|
|
|
head = {
|
|
|
|
title.text = page.title;
|
|
|
|
meta.description = page.description;
|
|
|
|
link.canonical = lib.head page.locations;
|
2024-11-13 15:24:41 +01:00
|
|
|
link.stylesheets = [
|
2024-11-13 15:24:41 +01:00
|
|
|
# TODO: allow enabling preload with a flag
|
2024-11-13 15:24:41 +01:00
|
|
|
{ href = "${page.link cfg.assets."style.css"}"; }
|
|
|
|
{ href = "${page.link cfg.assets."fonts.css"}"; }
|
|
|
|
];
|
2024-11-13 15:24:41 +01:00
|
|
|
};
|
2024-11-13 15:24:41 +01:00
|
|
|
body.content = [
|
2024-11-13 15:24:41 +01:00
|
|
|
''
|
|
|
|
<header>
|
2024-11-13 15:24:41 +01:00
|
|
|
<input type="checkbox" id="menu-toggle">
|
2024-11-13 15:24:41 +01:00
|
|
|
${lib.indent " " (cfg.menus.main.outputs.html page)}
|
|
|
|
</header>
|
|
|
|
''
|
2024-11-13 15:24:41 +01:00
|
|
|
{
|
|
|
|
section = {
|
2024-11-13 15:24:41 +01:00
|
|
|
attrs = { };
|
2024-11-13 15:24:41 +01:00
|
|
|
heading.content = page.title;
|
|
|
|
content = [
|
|
|
|
(cfg.templates.html.markdown { inherit (page) name body; })
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
2024-11-13 15:24:41 +01:00
|
|
|
];
|
2024-11-13 15:24:41 +01:00
|
|
|
};
|
2024-11-13 15:24:41 +01:00
|
|
|
});
|
2024-11-13 15:24:41 +01:00
|
|
|
}
|