From ea77a44d1abd31120ce3caa21d1e212a41b4cf83 Mon Sep 17 00:00:00 2001 From: valentin gagarin Date: Wed, 13 Nov 2024 15:24:41 +0100 Subject: [PATCH] split content types into module --- website/content/default.nix | 2 + website/structure/content-types.nix | 97 +++++++++++++++++++++++++++++ website/structure/default.nix | 91 +-------------------------- 3 files changed, 101 insertions(+), 89 deletions(-) create mode 100644 website/structure/content-types.nix diff --git a/website/content/default.nix b/website/content/default.nix index a53fdba..397ffb7 100644 --- a/website/content/default.nix +++ b/website/content/default.nix @@ -5,6 +5,8 @@ in { imports = with lib.fileset; toList (difference (fileFilter ({ hasExt, ... }: hasExt "nix") ./.) ./default.nix); + collections.news.type = config.content-types.article; + pages.index = { title = "Fediversity"; locations = [ diff --git a/website/structure/content-types.nix b/website/structure/content-types.nix new file mode 100644 index 0000000..22b0796 --- /dev/null +++ b/website/structure/content-types.nix @@ -0,0 +1,97 @@ +{ config, lib, options, ... }: +let + inherit (lib) + mkOption + types + ; + cfg = config; +in +{ + options = { + content-types = mkOption { + description = "Content types"; + type = with types; attrsOf deferredModule; + }; + }; + config.content-types = { + page = { name, config, ... }: { + options = { + name = mkOption { + description = "Symbolic name for the page, used as a human-readable identifier"; + type = types.str; + default = name; + }; + title = mkOption { + description = "Page title"; + type = types.str; + default = name; + }; + locations = mkOption { + description = '' + List of historic output locations for the resulting file + + The first element is the canonical location. + All other elements are used to create redirects to the canonical location. + ''; + type = with types; nonEmptyListOf str; + }; + link = mkOption { + description = "Helper function for transparent linking to other pages"; + type = with types; functionTo str; + default = target: "TODO: compute the relative path based on `locations`"; + }; + outPath = mkOption { + description = '' + Location of the page, used for transparently creating links + ''; + type = types.str; + default = lib.head config.locations; + }; + 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; + }; + template = mkOption { + description = '' + Function that converts the page contents to files + ''; + type = with types; functionTo (functionTo options.files.type); + default = cfg.templates.page; + }; + }; + }; + + article = { config, collectionName, ... }: { + imports = [ cfg.content-types.page ]; + options = { + date = mkOption { + description = "Publication date"; + type = with types; nullOr str; + default = null; + }; + author = mkOption { + description = "Page author"; + type = with types; nullOr (either str (listOf str)); + default = null; + }; + }; + config.name = lib.slug config.title; + config.outPath = "${collectionName}/${lib.head config.locations}"; + config.template = cfg.templates.article; + }; + }; +} diff --git a/website/structure/default.nix b/website/structure/default.nix index d53316d..b99cf19 100644 --- a/website/structure/default.nix +++ b/website/structure/default.nix @@ -5,101 +5,15 @@ let types ; cfg = config; - types' = { - article = { config, collectionName, ... }: { - imports = [ types'.page ]; - options = { - date = mkOption { - description = "Publication date"; - type = with types; nullOr str; - default = null; - }; - author = mkOption { - description = "Page author"; - type = with types; nullOr (either str (listOf str)); - default = null; - }; - }; - config.name = lib.slug config.title; - config.outPath = "${collectionName}/${lib.head config.locations}"; - config.template = cfg.templates.article; - }; - - page = { name, config, ... }: { - options = { - name = mkOption { - description = "Symbolic name for the page, used as a human-readable identifier"; - type = types.str; - default = name; - }; - title = mkOption { - description = "Page title"; - type = types.str; - default = name; - }; - locations = mkOption { - description = '' - List of historic output locations for the resulting file - - The first element is the canonical location. - All other elements are used to create redirects to the canonical location. - ''; - type = with types; nonEmptyListOf str; - }; - link = mkOption { - description = "Helper function for transparent linking to other pages"; - type = with types; functionTo str; - default = target: "TODO: compute the relative path based on `locations`"; - }; - outPath = mkOption { - description = '' - Location of the page, used for transparently creating links - ''; - type = types.str; - default = lib.head config.locations; - }; - 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; - }; - template = mkOption - { - description = '' - Function that converts the page contents to files - ''; - type = with types; functionTo (functionTo options.files.type); - default = cfg.templates.page; - }; - }; - }; - }; in { - # TODO: split out: - # - extra module system types into lib' - # - page and article types into their own module values under structure/${page,article}.nix - # yes, actually. those types should probably be configurable - config.collections.news.type = types'.article; + imports = [ ./content-types.nix ]; options.pages = mkOption { description = '' Collection of pages on the site ''; - type = with types; attrsOf (submodule types'.page); + type = with types; attrsOf (submodule config.content-types.page); }; options.collections = mkOption @@ -222,7 +136,6 @@ in in pages // collections; - options.build = mkOption { description = '' The final output of the web site