about summary refs log tree commit diff
path: root/web/todolist/default.nix
blob: 187830e736e16ece791920b16d5c6df39787b1a6 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Generates a simple web view of open TODOs in the depot.
#
# Only TODOs that match the form 'TODO($username)' are considered, and
# only for users that are known to us.
{ depot, lib, ... }:

with depot.nix.yants;

let
  inherit (depot.third_party)
    jq
    ripgrep
    runCommandNoCC
    writeText
    ;

  inherit (builtins)
    elem
    filter
    fromJSON
    head
    readFile
    ;

  inherit (lib) concatStringsSep;

  # We should extract this from TVL slapd, but that data is not easily
  # accessible right now.
  knownUsers = [
    "tazjin"
    "riking"
    "Profpatsch"
    "grfn"
    "lukegb"
  ];

  todo = struct {
    file = string;
    line = int;
    todo = string;
    user = string;
  };

  allTodos = fromJSON (readFile (runCommandNoCC "depot-todos.json" {} ''
    ${ripgrep}/bin/rg --json 'TODO\(\w+\):.*$' ${depot.depotPath} | \
      ${jq}/bin/jq -s -f ${./extract-todos.jq} > $out
  ''));

  knownUserTodos = filter (todos: elem (head todos).user knownUsers) allTodos;

  fileLink = defun [ todo string ] (t:
    ''<a style="color: inherit;"
         href="https://cs.tvl.fyi/depot/-/blob/${t.file}#L${toString t.line}">
      //${t.file}:${toString t.line}</a>'');

  todoElement = defun [ todo string ] (t: ''
    <p>At ${fileLink t}:</p>
    <blockquote>${t.todo}</blockquote>

  '');

  userParagraph = todos:
  let user = (head todos).user;
  in ''
    <p>
      <h3>${user}</h3>
      ${concatStringsSep "\n" (map todoElement todos)}
    </p>
    <hr>
  '';

  todoPage = writeText "index.html" ''
    <!DOCTYPE html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <meta name="description" content="TVL's todo-list">
      <link rel="stylesheet" type="text/css" href="static/tazjin.css" media="all">
      <link rel="icon" type="image/webp" href="static/favicon.webp">
      <title>TVL's todo-list</title>
      <style>
        svg {
          max-width: inherit;
          height: auto;
        }
      </style>
    </head>
    <body class="dark">
      <header>
        <h1><a class="blog-title" href="/">The Virus Lounge's todo-list</a> </h1>
        <hr>
      </header>
      <main>
      ${concatStringsSep "\n" (map userParagraph knownUserTodos)}
      </main>
      <footer>
        <p class="footer">
          <a class="uncoloured-link" href="https://tvl.fyi">homepage</a>
          |
          <a class="uncoloured-link" href="https://cs.tvl.fyi/depot/-/blob/README.md">code</a>
          |
          <a class="uncoloured-link" href="https://cl.tvl.fyi">reviews</a>
        </p>
        <p class="lod">ಠ_ಠ</p>
      </footer>
    </body>
  '';

in runCommandNoCC "tvl-todos" {} ''
  mkdir $out
  cp ${todoPage} $out/index.html
  ln -s ${depot.web.tvl}/static $out/static
''