{ config, options, lib, pkgs, ... }: let inherit (lib) mkOption types ; cfg = config; in { imports = [ ./content-types.nix ]; options.pages = mkOption { description = '' Collection of pages on the site ''; type = with types; attrsOf (submodule config.content-types.page); }; options.collections = mkOption { description = '' Named collections of unnamed pages Define the content type of a new collection `example` to be `article`: ```nix config.collections.example.type = config.types.article; ``` Add a new entry to the `example` collection: ```nix config.collections.example.entry = { # contents here } ``` ''; type = with types; attrsOf (submodule ({ name, config, ... }: { options = { type = mkOption { description = "Type of entries in the collection"; type = types.deferredModule; }; entry = mkOption { description = "An entry in the collection"; type = types.collection (types.submodule ({ _module.args.collection = config.entry; _module.args.collectionName = name; imports = [ config.type ]; })); }; }; })); }; options.templates = mkOption { description = '' Collection of named functions to convert page contents to files Each template function takes the complete site `config` and the page data structure. ''; type = with types; attrsOf (functionTo (functionTo options.files.type)); }; # TODO: split out templates and all related helper junk into `../presentation` config.templates = let commonmark = name: markdown: pkgs.runCommand "${name}.html" { buildInputs = [ pkgs.cmark ]; } '' cmark ${builtins.toFile "${name}.md" markdown} > $out ''; in { page = lib.mkDefault (config: page: { # TODO: create static redirects from `tail page.locations` # TODO: reconsider using `page.outPath` and what to put into `locations`. # maybe we can avoid having ".html" suffixes there. # since templates can output multiple files, `html` is merely one of many things we *could* produce. ${page.outPath} = builtins.toFile "${page.name}.html" ''