about summary refs log tree commit diff
path: root/users/wpcarro/website/blog/default.nix
blob: bef06cad74571b4232c3609325aad08e66ce0c0b (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{ depot, lib, pkgs, ... }:

with depot.nix.yants;

let
  inherit (builtins) hasAttr filter readFile;
  inherit (depot.web.blog) post includePost renderPost;
  inherit (depot.users) wpcarro;
  inherit (pkgs) runCommandNoCC;

  config = {
    name = "wpcarro's blog";
    baseUrl = "https://wpcarro.dev/blog";
  };

  posts = filter includePost (list post (import ./posts.nix));

  rendered = runCommandNoCC "wpcarros-blog" {} ''
    mkdir -p $out

    ${lib.concatStringsSep "\n" (map (post:
      "cp ${renderPost config post} $out/${post.key}.html"
    ) posts)}
  '';

  formatDate = date: readFile (runCommandNoCC "date" {} ''
    date --date='@${toString date}' '+%B %e, %Y' > $out
  '');

  postsList = pkgs.writeText "index.html" ''
    <div class="max-w-sm md:max-w-prose mx-auto">
      <section class="pt-8 pb-14">
        <p class="font-bold pb-4">Personal blog by <a class="font-bold text-blue-600 hover:underline" href="https://wpcarro.dev">wpcarro</a>.</p>
        <p class="text-gray-500">&gt; Half-baked musings lossily encoded.</p>
        <p class="text-gray-500">&gt; - misc reviewer</p>
      </section>
      <ul>
        ${lib.concatStringsSep "\n" (map (post: ''
          <li class="pb-10">
            <h2 class="text-bold font-2xl ">
              <a class="font-bold text-blue-600 hover:underline" href="${config.baseUrl}/${post.key}.html">
                ${post.title}
              </a>
            </h2>
            <p class="text-gray-500">
              ${formatDate post.date}
            </p>
          </li>
        '') posts)}
      </ul>
    </div>
  '';
in {
  inherit posts rendered config;

  root = runCommandNoCC "wpcarros-blog" {} ''
    mkdir -p $out

    cat ${wpcarro.website.header} \
        ${postsList} \
        ${wpcarro.website.addendum} > $out/index.html
  '';
}