about summary refs log tree commit diff
path: root/users/wpcarro/website/blog/default.nix
blob: 713c42a83b3344cb8dea81604fc71f6d18628402 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{ 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
  '';
}