tvl-depot/users/wpcarro/website/blog/default.nix
William Carroll e107311cb8 refactor(wpcarro/website): Prefer substituteAll
`substituteAll` supports templating with @variables@, which I think really
cleans things up.

Change-Id: Icfad15ac9e174495ba02260d817f7330f1616c6f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4722
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Tested-by: BuildkiteCI
2021-12-28 00:09:36 +00:00

48 lines
1.2 KiB
Nix

{ depot, lib, pkgs, ... }:
with depot.nix.yants;
let
inherit (builtins) hasAttr filter readFile;
inherit (depot.web.blog) post includePost renderPost;
inherit (depot.users) wpcarro;
config = {
name = "wpcarro's blog";
baseUrl = "https://wpcarro.dev/blog";
footer = "";
};
posts = filter includePost (list post (import ./posts.nix));
rendered = pkgs.runCommandNoCC "wpcarros-blog-posts" {} ''
mkdir -p $out
${lib.concatStringsSep "\n" (map (post:
"cp ${renderPost config post} $out/${post.key}.html"
) posts)}
'';
formatDate = date: readFile (pkgs.runCommandNoCC "date" {} ''
date --date='@${toString date}' '+%B %e, %Y' > $out
'');
postsHtml = readFile (pkgs.substituteAll {
src = ./fragments/posts.html;
postsHtml = lib.concatStringsSep "\n" (map toPostHtml posts);
});
toPostHtml = post: readFile (pkgs.substituteAll {
src = ./fragments/post.html;
postUrl = "${config.baseUrl}/${post.key}.html";
postTitle = post.title;
postDate = formatDate post.date;
});
in {
inherit posts rendered config;
root = pkgs.runCommandNoCC "wpcarros-blog" {} ''
mkdir -p $out
cp ${wpcarro.website.render postsHtml} $out/index.html
'';
}