about summary refs log tree commit diff
path: root/users/Profpatsch/blog
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-08-07T19·17+0200
committerProfpatsch <mail@profpatsch.de>2021-11-13T00·57+0000
commit81e39b51cdd11745437a4925df507c78d5406633 (patch)
tree5a7b6fb8542affce74baaea14dd416441ad2a2a6 /users/Profpatsch/blog
parentd4f4b0f6d4fc96067abe89053ee27e5ac9d1c978 (diff)
feat(users/Profpatsch/blog): Add projects section r/3047
A new section for my awesome website.

Change-Id: I6c624aa0bfaf82aff943431da7499bec1d842c67
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3291
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch/blog')
-rw-r--r--users/Profpatsch/blog/default.nix113
1 files changed, 106 insertions, 7 deletions
diff --git a/users/Profpatsch/blog/default.nix b/users/Profpatsch/blog/default.nix
index 6cad24507b..e3d32947c9 100644
--- a/users/Profpatsch/blog/default.nix
+++ b/users/Profpatsch/blog/default.nix
@@ -15,13 +15,18 @@ let
       name = "Notes";
       page = router;
     }
+    {
+      route = [ "projects" ];
+      name = "Projects";
+      # page = projects;
+    }
   ];
 
   # /notes/*
   notes = [
     {
       route = [ "notes" "preventing-oom" ];
-      name = "Preventing OOM";
+      name = "Preventing out-of-memory (OOM) errors on Linux";
       page = renderNote "preventing-oom" ./notes/preventing-oom.md;
     }
     {
@@ -31,6 +36,24 @@ let
     }
   ];
 
+  projects = [
+    {
+      name = "lorri";
+      description = "<code>nix-shell</code> 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 <a href="https://yarnpkg.com/"><code>yarn</code> Javascript package manager</a>'';
+      link = "https://github.com/Profpatsch/yarn2nix";
+    }
+  ];
+
   # convert a note to html via lowdown
   renderNote = name: note: depot.nix.runExecline "${name}.html" {} [
     "importas" "out" "out"
@@ -52,6 +75,18 @@ let
     (cdbMake "notes-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"
@@ -62,7 +97,17 @@ let
     "redirfd" "-w" "1" "$out"
   ] ++ cmd);
 
-  index = runExeclineStdout "index" {
+  notes-index-html =
+    let o = notesFullRoute;
+    in ''
+      <ul>
+      ${scope o (o: ''
+        <li><a href="${str o.route}">${esc o.name}</a></li>
+      '')}
+      </ul>
+    '';
+
+  notes-index  = runExeclineStdout "notes-index" {
     stdin = depot.users.Profpatsch.netencode.gen.dwim notesFullRoute;
   } [
     "withstdinas" "-in" "TEMPLATE_DATA"
@@ -70,7 +115,7 @@ let
       bins.printf ''
         <ul>
         {{#.}}
-          <li><a href="{{route}}">{{name}}<a></li>
+          <li><a href="{{route}}">{{name}}</a></li>
         {{/.}}
         </ul>
       ''
@@ -78,13 +123,57 @@ let
     depot.users.Profpatsch.netencode.netencode-mustache
   ];
 
+  # A simple mustache-inspired string interpolation combinator
+  # that takes an object and a template (a function from o to string)
+  # and returns a string.
+  scope = o: tpl:
+    if builtins.typeOf o == "list" then
+      lib.concatMapStringsSep "\n" tpl o
+    else if builtins.typeOf o == "set" then
+      tpl o
+    else throw "${lib.generators.toPretty {} o} not allowed in template";
+
+  # string-escape html (TODO)
+  str = s: s;
+  # html-escape (TODO)
+  esc = s: s;
+  html = s: s;
+
+  projects-index-html =
+  let o = projects;
+  in ''
+    <dl>
+    ${scope o (o: ''
+      <dt><a href="${str o.link}">${esc o.name}</a></dt>
+      <dd>${html o.description}</dd>
+    '')}
+    </dl>
+  '';
+
+  projects-index = runExeclineStdout "projects-index" {
+    stdin = depot.users.Profpatsch.netencode.gen.dwim projects;
+  } [
+    "withstdinas" "-in" "TEMPLATE_DATA"
+    "pipeline" [
+      bins.printf ''
+        <dl>
+        {{#.}}
+          <dt><a href="{{link}}">{{name}}</a></dt>
+          <dd>{{{description}}}</dd>
+        {{/.}}
+        </dl>
+      ''
+    ]
+    depot.users.Profpatsch.netencode.netencode-mustache
+  ];
+
   arglibNetencode = val: depot.nix.writeExecline "arglib-netencode" { } [
     "export" "ARGLIB_NETENCODE" (depot.users.Profpatsch.netencode.gen.dwim val)
     "$@"
   ];
 
   # A simple http server that serves the site. Yes, it’s horrible.
-  notes-server = { port }: depot.nix.writeExecline "blog-server" {} [
+  site-server = { port }: depot.nix.writeExecline "blog-server" {} [
     (depot.users.Profpatsch.lib.runInEmptyEnv [ "PATH" ])
     bins.s6-tcpserver "127.0.0.1" port
     bins.time "--format=time: %es" "--"
@@ -101,9 +190,15 @@ let
     "if" [ depot.tools.eprintf "GET \${path}\n" ]
     runOr return404
     "backtick" "-ni" "TEMPLATE_DATA" [
+      # TODO: factor this out of here, this is routing not serving
       "ifelse" [ bins.test "$path" "=" "/notes" ]
         [ "export" "content-type" "text/html"
-          "export" "serve-file" index
+          "export" "serve-file" notes-index
+          depot.users.Profpatsch.netencode.env-splice-record
+        ]
+      "ifelse" [ bins.test "$path" "=" "/projects" ]
+        [ "export" "content-type" "text/html"
+          "export" "serve-file" projects-index
           depot.users.Profpatsch.netencode.env-splice-record
         ]
       # TODO: ignore potential query arguments. See 404 message
@@ -233,8 +328,12 @@ let
 in depot.nix.utils.drvTargets {
    inherit
     router
-    notes-server
-    index
+    depotCgitLink
+    site-server
+    notes-index
+    notes-index-html
+    projects-index
+    projects-index-html
     router-lookup
     ;