{ depot, pkgs, lib, ... }:
let
bins = depot.nix.getBins pkgs.lowdown [ "lowdown" ]
// depot.nix.getBins pkgs.cdb [ "cdbget" "cdbmake" "cdbdump" ]
// depot.nix.getBins pkgs.coreutils [ "mv" "cat" "printf" "test" ]
// depot.nix.getBins pkgs.s6-networking [ "s6-tcpserver" ]
// depot.nix.getBins pkgs.time [ "time" ]
;
# /
toplevel = [
{
route = [ "notes" ];
name = "Notes";
page = router;
}
{
route = [ "projects" ];
name = "Projects";
# page = projects;
}
];
# /notes/*
notes = [
{
route = [ "notes" "preventing-oom" ];
name = "Preventing out-of-memory (OOM) errors on Linux";
page = markdownToHtml "preventing-oom" ./notes/preventing-oom.md;
}
{
route = [ "notes" "rust-string-conversions" ];
name = "Converting between different String types in Rust";
page = markdownToHtml "rust-string-conversions" ./notes/rust-string-conversions.md;
}
];
projects = [
{
name = "lorri";
description = "nix-shell
replacement for projects";
link = "https://github.com/nix-community/lorri";
}
{
name = "netencode";
description = ''A human-readble nested data exchange format inspired by netstrings and bencode.'';
link = depotCgitLink { relativePath = "users/Profpatsch/netencode/README.md"; };
}
{
name = "yarn2nix";
description = ''nix dependency generator for the yarn
Javascript package manager'';
link = "https://github.com/Profpatsch/yarn2nix";
}
];
posts = [
{
date = "2017-05-04";
title = "Ligature Emulation in Emacs";
subtitle = "It’s not pretty, but the results are";
description = "How to set up ligatures using prettify-symbols-mode
and the Hasklig/FiraCode fonts.";
page = markdownToHtml "2017-05-04-ligature-emluation-in-emacs" ./posts/2017-05-04-ligature-emulation-in-emacs.md;
route = [ "posts" "2017-05-04-ligature-emluation-in-emacs" ];
tags = ["emacs"];
}
];
# convert a markdown file to html via lowdown
markdownToHtml = name: note: depot.nix.runExecline "${name}.html" {} [
"importas" "out" "out"
bins.lowdown "-s" "-Thtml" "-o" "$out" note
];
# all notes with `route` converted to an absolute path
notesFullRoute = lib.pipe notes [
(map (x@{route, ...}: x // { route = mkRoute route; }))
];
# all posts with `route` converted to an absolute path
postsFullRoute = lib.pipe posts [
(map (x@{route, ...}: x // { route = mkRoute route; }))
];
# a cdb from route to a netencoded version of data for each route
router = lib.pipe (notesFullRoute ++ postsFullRoute) [
(map (x: {
name = x.route;
value = depot.users.Profpatsch.netencode.gen.dwim x;
}))
lib.listToAttrs
(cdbMake "router")
];
# Create a link to the given source file/directory, given the relative path in the depot repo.
# Checks that the file exists at evaluation time.
depotCgitLink = {
# relative path from the depot root (without leading /).
relativePath
}:
assert
(lib.assertMsg
(builtins.pathExists (depot.path + "/" + relativePath))
"depotCgitLink: path /${relativePath} does not exist in depot");
"https://code.tvl.fyi/tree/${relativePath}";
# look up a route by path ($1)
router-lookup = depot.nix.writeExecline "router-lookup" { readNArgs = 1; } [
cdbLookup router "$1"
];
runExeclineStdout = name: args: cmd: depot.nix.runExecline name args ([
"importas" "-ui" "out" "out"
"redirfd" "-w" "1" "$out"
] ++ cmd);
notes-index-html =
let o = notesFullRoute;
in ''