From 3a36a6cf2949582b5cee2780686ada2df1f17767 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 --- website/presentation/default.nix | 54 ++++++++++-------------------- website/presentation/templates.nix | 17 ++++++++++ 2 files changed, 34 insertions(+), 37 deletions(-) create mode 100644 website/presentation/templates.nix diff --git a/website/presentation/default.nix b/website/presentation/default.nix index bb42a727..ca49c9a7 100644 --- a/website/presentation/default.nix +++ b/website/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/website/presentation/templates.nix b/website/presentation/templates.nix new file mode 100644 index 00000000..2de9d107 --- /dev/null +++ b/website/presentation/templates.nix @@ -0,0 +1,17 @@ +{ lib }: +{ + html = { head, body }: '' + + + + + + + ${lib.indent " " head} + + + ${lib.indent " " body} + + + ''; +}