From 656fd790a21a96ad90eb31b452c9824f2be810a8 Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 14 Oct 2024 13:18:20 +0200 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 bb42a72..ca49c9a 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 0000000..2de9d10 --- /dev/null +++ b/presentation/templates.nix @@ -0,0 +1,17 @@ +{ lib }: +{ + html = { head, body }: '' + + + + + + + ${lib.indent " " head} + + + ${lib.indent " " body} + + + ''; +}