extract generic document type

This commit is contained in:
Valentin Gagarin 2024-10-15 13:40:08 +02:00
parent e962f92db8
commit 765e34754b

View file

@ -14,18 +14,14 @@ in
}; };
}; };
config.content-types = { config.content-types = {
page = { name, config, ... }: { document = { name, config, ... }: {
options = { options = {
name = mkOption { name = mkOption {
description = "Symbolic name, used as a human-readable identifier"; description = "Symbolic name, used as a human-readable identifier";
type = types.str; type = types.str;
default = name; default = name;
}; };
title = mkOption {
description = "Page title";
type = types.str;
default = name;
};
locations = mkOption { locations = mkOption {
description = '' description = ''
List of historic output locations for the resulting file List of historic output locations for the resulting file
@ -40,6 +36,7 @@ in
type = with types; functionTo str; type = with types; functionTo str;
default = target: "TODO: compute the relative path based on `locations`"; default = target: "TODO: compute the relative path based on `locations`";
}; };
# TODO: may not need it when using `link`; could repurpose it to render the default template
outPath = mkOption { outPath = mkOption {
description = '' description = ''
Location of the page, used for transparently creating links Location of the page, used for transparently creating links
@ -47,6 +44,28 @@ in
type = types.str; type = types.str;
default = lib.head config.locations; default = lib.head config.locations;
}; };
# TODO: maybe it would even make sense to split routing and rendering altogether.
# in that case, templates would return strings, and a different
# piece of the machinery resolves rendering templates to files
# using `locations`.
# then we'd have e.g. `templates.html` and `templates.atom` for
# different output formats.
template = mkOption {
description = ''
Function that converts the page contents to files
'';
type = with types; functionTo (functionTo options.files.type);
};
};
};
page = { name, config, ... }: {
imports = [ cfg.content-types.document ];
options = {
title = mkOption {
description = "Page title";
type = types.str;
default = name;
};
description = mkOption { description = mkOption {
description = '' description = ''
One-sentence description of page contents One-sentence description of page contents
@ -65,14 +84,8 @@ in
''; '';
type = types.str; type = types.str;
}; };
template = mkOption {
description = ''
Function that converts the page contents to files
'';
type = with types; functionTo (functionTo options.files.type);
default = cfg.templates.page;
};
}; };
config.template = cfg.templates.page;
}; };
article = { config, collectionName, ... }: { article = { config, collectionName, ... }: {
@ -91,7 +104,7 @@ in
}; };
config.name = lib.slug config.title; config.name = lib.slug config.title;
config.outPath = "${collectionName}/${lib.head config.locations}"; config.outPath = "${collectionName}/${lib.head config.locations}";
config.template = cfg.templates.article; config.template = lib.mkForce cfg.templates.article;
}; };
named-link = { ... }: { named-link = { ... }: {