tvl-depot/users/wpcarro/website/blog/default.nix
William Carroll ca6be786a1 chore(wpcarro/website): Templatize website
Preferring billandhiscomputer.com in lieu of wpcarro.dev. wpcarro is a bit of a
tough username for others to remember and for me to say out-loud (it usually
involves me spelling it and explaining to others why Carroll is missing
2x-Ls). I think it's time for a change.

During the transition, I don't want to deal with stale links to
https://wpcarro.dev, so I'm templatizing more of my website and blog so that
these values can be replaced.

Expect more forthcoming changes.

Change-Id: Ic2f5519e6b0d76fcb8b737bf50009e8388f1b178
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4754
Tested-by: BuildkiteCI
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
2022-01-08 05:33:02 +00:00

43 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.website) domain renderTemplate withBrand;
config = {
name = "bill and his blog";
baseUrl = "https://${domain}/blog";
footer = "";
};
posts = filter includePost (list post (import ./posts.nix));
rendered = pkgs.runCommandNoCC "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 = renderTemplate ./fragments/posts.html {
postsHtml = lib.concatStringsSep "\n" (map toPostHtml posts);
};
toPostHtml = post: readFile (renderTemplate ./fragments/post.html {
postUrl = "${config.baseUrl}/posts/${post.key}.html";
postTitle = post.title;
postDate = formatDate post.date;
});
in pkgs.runCommandNoCC "blog" {} ''
mkdir -p $out
cp ${withBrand (readFile postsHtml)} $out/index.html
cp -r ${rendered} $out/posts
''