From 6a22b197ac6187d059982ca6f4e30d7e610373ae Mon Sep 17 00:00:00 2001 From: valentin gagarin Date: Wed, 13 Nov 2024 15:24:41 +0100 Subject: [PATCH] split out template library --- presentation/default.nix | 54 ++++++++++++-------------------------- presentation/templates.nix | 17 ++++++++++++ 2 files changed, 34 insertions(+), 37 deletions(-) create mode 100644 presentation/templates.nix diff --git a/presentation/default.nix b/presentation/default.nix index bb42a727..ca49c9a7 100644 --- a/presentation/default.nix +++ b/presentation/default.nix @@ -4,6 +4,7 @@ let mkOption types ; + templates = import ./templates.nix { inherit lib; }; in { options.templates = mkOption { @@ -30,46 +31,25 @@ in # 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" '' - - - - - - - ${page.title} - - - - - ${lib.indent " " (builtins.readFile (commonmark page.name page.body))} - - - ''; + ${page.outPath} = builtins.toFile "${page.name}.html" (templates.html { + head = '' + ${page.title} + + + ''; + body = builtins.readFile (commonmark page.name page.body); + }); }); article = lib.mkDefault (config: page: { # TODO: create static redirects from `tail page.locations` - ${page.outPath} = builtins.toFile "${page.name}.html" '' - - - - - - - ${page.title} - - ${with lib; - if ! isNull page.author then - '''' - else "" - } - - - - ${lib.indent " " (builtins.readFile (commonmark page.name page.body))} - - - ''; + ${page.outPath} = builtins.toFile "${page.name}.html" (templates.html { + head = '' + ${page.title} + + + ''; + body = builtins.readFile (commonmark page.name page.body); + }); }); }; diff --git a/presentation/templates.nix b/presentation/templates.nix new file mode 100644 index 00000000..2de9d107 --- /dev/null +++ b/presentation/templates.nix @@ -0,0 +1,17 @@ +{ lib }: +{ + html = { head, body }: '' + + + + + + + ${lib.indent " " head} + + + ${lib.indent " " body} + + + ''; +}