From b5841bd227fa0024c3464cb9fc64b2c4ccebbf8a Mon Sep 17 00:00:00 2001 From: valentin gagarin Date: Wed, 13 Nov 2024 15:24:41 +0100 Subject: [PATCH] add stylesheet with fonts --- presentation/style.css | 12 +++++++++ presentation/style.nix | 53 ++++++++++++++++++++++++++++++++++++++ presentation/templates.nix | 3 ++- structure/assets.nix | 3 +-- structure/default.nix | 2 +- structure/page.nix | 4 +++ 6 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 presentation/style.css create mode 100644 presentation/style.nix diff --git a/presentation/style.css b/presentation/style.css new file mode 100644 index 00000000..b0e81a04 --- /dev/null +++ b/presentation/style.css @@ -0,0 +1,12 @@ +body { + font-family: Heebo, sans-serif; + padding: 1em; + max-width: 50em; + margin: auto; +} + +h1, h2, h3, h4, h5, h6 +{ + font-family: Signika, sans-serif; +} + diff --git a/presentation/style.nix b/presentation/style.nix new file mode 100644 index 00000000..c90038dd --- /dev/null +++ b/presentation/style.nix @@ -0,0 +1,53 @@ +{ config, lib, pkgs, ... }: { + config.assets."style.css".path = ./style.css; + config.assets."fonts.css".path = with lib; builtins.toFile "fonts.css" (join "\n" (map + (font: '' + @font-face { + font-family: '${font.name}'; + font-style: normal; + font-weight: ${toString font.weight}; + src: url(/${head config.assets.${font.file}.locations}) format('woff2'); + } + '') + ( + (crossLists (name: file: weight: { inherit name file weight; }) + [ [ "Signika " ] [ "signika-extended.woff2" "signika.woff2" ] [ 500 700 ] ] + ) + ++ + (crossLists (name: file: weight: { inherit name file weight; }) + [ [ "Heebo " ] [ "heebo-extended.woff2" "heebo.woff2" ] [ 400 600 ] ] + ) + ) + )); + + # TODO: get directly from https://github.com/google/fonts + # and compress with https://github.com/fonttools/fonttools + config.assets."signika-extended.woff2" = { + path = pkgs.fetchurl { + url = "https://fonts.gstatic.com/s/signika/v25/vEFO2_JTCgwQ5ejvMV0Ox_Kg1UwJ0tKfX6bOjM7sfA.woff2"; + hash = "sha256-6xM7cHYlTKNf1b0gpqhPJjwOoZfxx9+u1e4JPYG2lKk="; + name = "signika-extended.woff2"; + }; + }; + config.assets."signika.woff2" = { + path = pkgs.fetchurl { + url = "https://fonts.gstatic.com/s/signika/v25/vEFO2_JTCgwQ5ejvMV0Ox_Kg1UwJ0tKfX6bBjM4.woff2"; + hash = "sha256-Yu0kGT3seb8Qtulu84wvY6nLyPXsRBO/JvTD2BQBtHg="; + name = "signika.woff2"; + }; + }; + config.assets."heebo-extended.woff2" = { + path = pkgs.fetchurl { + url = "https://fonts.gstatic.com/s/heebo/v26/NGS6v5_NC0k9P9H2TbE.woff2"; + hash = "sha256-lk3+fFEqYWbHHGyXkdhKnOOMGS9m5ZbbxQcRQCSlxDE="; + name = "heebo-extended.woff2"; + }; + }; + config.assets."heebo.woff2" = { + path = pkgs.fetchurl { + url = "https://fonts.gstatic.com/s/heebo/v26/NGS6v5_NC0k9P9H4TbFzsQ.woff2"; + hash = "sha256-JWnjYlbcNsg6KCJnRRjECL2HnZGJOBTMtdutWBNza4Q="; + name = "heebo.woff2"; + }; + }; +} diff --git a/presentation/templates.nix b/presentation/templates.nix index d23ee1fb..6a588596 100644 --- a/presentation/templates.nix +++ b/presentation/templates.nix @@ -55,7 +55,8 @@ in # TODO: create static redirects from `tail .locations` (acc: elem: acc // (mapAttrs' (type: value: { name = head elem.locations + optionalString (type != "") ".${type}"; - value = builtins.toFile + value = if isStorePath value then value else + builtins.toFile (elem.name + optionalString (type != "") ".${type}") (toString value); })) diff --git a/structure/assets.nix b/structure/assets.nix index ff534286..11b143fb 100644 --- a/structure/assets.nix +++ b/structure/assets.nix @@ -16,8 +16,7 @@ in options.path = mkOption { type = types.path; }; - config.name = builtins.baseNameOf config.path; - config.outputs."" = builtins.readFile config.path; + config.outputs."" = if lib.isStorePath config.path then config.path else "${config.path}"; })); default = { }; }; diff --git a/structure/default.nix b/structure/default.nix index a13bb95f..232c6f1e 100644 --- a/structure/default.nix +++ b/structure/default.nix @@ -74,7 +74,7 @@ in description = '' Representations of the document in different formats ''; - type = with types; attrsOf (either str attrs); + type = with types; attrsOf (either attrs pathInStore); }; }; }; diff --git a/structure/page.nix b/structure/page.nix index 3578385b..8b9cf17e 100644 --- a/structure/page.nix +++ b/structure/page.nix @@ -54,6 +54,10 @@ in title.text = page.title; meta.description = page.description; link.canonical = lib.head page.locations; + link.stylesheets = [ + { href = "${page.link cfg.assets."style.css"}"; } + { href = "${page.link cfg.assets."fonts.css"}"; } + ]; }; body.content = [ (cfg.menus.main.outputs.html page)