tvl-depot/web/todolist/default.nix
Vincent Ambo aa122cbae7 style: format entire depot with nixpkgs-fmt
This CL can be used to compare the style of nixpkgs-fmt against other
formatters (nixpkgs, alejandra).

Change-Id: I87c6abff6bcb546b02ead15ad0405f81e01b6d9e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4397
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: lukegb <lukegb@tvl.fyi>
Reviewed-by: wpcarro <wpcarro@gmail.com>
Reviewed-by: Profpatsch <mail@profpatsch.de>
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: cynthia <cynthia@tvl.fyi>
Reviewed-by: edef <edef@edef.eu>
Reviewed-by: eta <tvl@eta.st>
Reviewed-by: grfn <grfn@gws.fyi>
2022-01-31 16:11:53 +00:00

116 lines
2.8 KiB
Nix

# 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, pkgs, ... }:
let
inherit (pkgs)
jq
ripgrep
runCommandNoCC
writeTextFile
;
inherit (builtins)
elem
filter
fromJSON
head
readFile
map
;
inherit (lib) concatStringsSep;
inherit (depot.nix.yants)
defun
int
string
struct
;
knownUsers = map (u: u.username) depot.ops.users;
todo = struct {
file = string;
line = int;
todo = string;
user = string;
};
allTodos = fromJSON (readFile (runCommandNoCC "depot-todos.json" { } ''
${ripgrep}/bin/rg --json 'TODO\(\w+\):.*$' ${depot.path} | \
${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>${fileLink t}:</p>
<blockquote>${t.todo}</blockquote>
'');
userParagraph = todos:
let user = (head todos).user;
in ''
<p>
<h3>
<a style="color:inherit; text-decoration: none;"
name="${user}"
href="#${user}">${user}</a>
</h3>
${concatStringsSep "\n" (map todoElement todos)}
</p>
<hr>
'';
staticUrl = "https://static.tvl.fyi/${depot.web.static.drvHash}";
in
writeTextFile {
name = "tvl-todos";
destination = "/index.html";
text = ''
<!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" media="all" href="${staticUrl}/tvl.css">
<link rel="icon" type="image/webp" href="${staticUrl}/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>
'';
}