From 895a679fd43f7e236135705aaee3d58201d32a1f Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 13 Nov 2021 12:38:49 +0100 Subject: pkgs/profpatsch.de: reference the blog and notes sections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This pulls in tvl, since the blog ist mostly over there. It uses `fetchGit`, so caveats may apply. It shouldn’t increase evaluation times very much, since the blog only uses a small subset of tvl. https://github.com/openlab-aux/vuizvui/issues/50 might apply. --- pkgs/profpatsch/profpatsch.de/default.nix | 86 ++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 20 deletions(-) (limited to 'pkgs/profpatsch/profpatsch.de/default.nix') diff --git a/pkgs/profpatsch/profpatsch.de/default.nix b/pkgs/profpatsch/profpatsch.de/default.nix index 9f15cd2a..92b8d35d 100644 --- a/pkgs/profpatsch/profpatsch.de/default.nix +++ b/pkgs/profpatsch/profpatsch.de/default.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, toNetstring, writeExecline, runExecline, getBins, writeRustSimple, netencode-rs, el-semicolon, el-substitute, el-exec, netencode, record-get }: +{ pkgs, tvl, lib, toNetstring, toNetstringList, writeExecline, runExecline, getBins, writeRustSimple, netencode-rs, el-semicolon, el-substitute, el-exec, netencode, record-get }: let bins = getBins pkgs.coreutils [ "ln" "mkdir" "echo" "printenv" "cat" "env" ] @@ -20,13 +20,23 @@ let "pipeline" [ bins.multitee "0-1,2" ] "$@" ]; - applyTemplate = name: templateNix: deps: + applyTemplate = { + name, + # the nix template file to import + templateNix, + # the page dependencies, attrset of path, relativeDir and relativeFile + pageDeps, + # html that should just be interpolated; + # will shadow any attrs in pageDeps of the same name + interpolateHtml ? {}, + }: pkgs.writeText name (import templateNix - (lib.mapAttrs - # relative to the root of the webpage - (k: v: "/" + (joinPath (v.relativeDir ++ [ v.relativeFile ]))) - deps)); + ((lib.mapAttrs + # relative to the root of the webpage + (k: v: "/" + (joinPath (v.relativeDir ++ [ v.relativeFile ]))) + pageDeps) + // interpolateHtml)); staticFiles = rec { @@ -43,13 +53,34 @@ let cssMain = { relativeDir = [ "css" ]; relativeFile = "main.css"; - path = applyTemplate "main.css" ./main.css.nix { - inherit - fontsQuattrocentoLatin - fontsOpenSansLatin - ; + path = applyTemplate { + name = "main.css"; + templateNix = ./main.css.nix; + pageDeps = { + inherit + fontsQuattrocentoLatin + fontsOpenSansLatin + ; + }; }; }; + cssConcatenated = + let + concatCss = cssFiles: runExecline "concat-css" { + stdin = toNetstringList (map (c: c.path) cssFiles); + } [ + "importas" "out" "out" + "forstdin" "-Ed" "" "css" + "redirfd" "-a" "1" "$out" + "redirfd" "-r" "0" "$css" + bins.cat + ]; + in { + relativeDir = [ "css" ]; + relativeFile = "concatenated.css"; + path = concatCss [cssNormalize cssMain]; + }; + fontsQuattrocentoLatin = { relativeDir = [ "fonts" ]; relativeFile = "quattrocento-latin.woff2"; @@ -78,15 +109,24 @@ let index_html = { relativeDir = []; relativeFile = "index.html"; - path = applyTemplate "index.html" ./index.html.nix { - inherit jsTalkies; - inherit cssNormalize cssMain; - inherit cv_pdf id_txt; - # preloading - inherit - fontsQuattrocentoLatin - fontsOpenSansLatin - ; + path = applyTemplate { + name = "index.html"; + templateNix = ./index.html.nix; + pageDeps = { + inherit jsTalkies; + inherit cssNormalize cssMain; + inherit cv_pdf id_txt; + # preloading + inherit + fontsQuattrocentoLatin + fontsOpenSansLatin + ; + }; + interpolateHtml = { + notes-html-snippet = tvl.users.Profpatsch.blog.notes-index-html; + projects-html-snippet = tvl.users.Profpatsch.blog.projects-index-html; + posts-html-snippet = tvl.users.Profpatsch.blog.posts-index-html; + }; }; }; toc = { @@ -96,6 +136,11 @@ let }; }; + concatenatedCss = + let mkRoute = css: { route = css.relativeDir ++ [ css.relativeFile ]; }; + in mkRoute staticFiles.cssConcatenated; + + importas-if = writeRustSimple "importas-if" { dependencies = [ netencode-rs el-substitute el-exec ]; # TODO: for some reason the skarnet linker flag @@ -168,5 +213,6 @@ in { websiteStatic record-get importas-if + concatenatedCss ; } -- cgit 1.4.1