From 81e39b51cdd11745437a4925df507c78d5406633 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 7 Aug 2021 21:17:32 +0200 Subject: feat(users/Profpatsch/blog): Add projects section 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 --- users/Profpatsch/blog/default.nix | 113 +++++++++++++++++++++++++++++++++++--- 1 file changed, 106 insertions(+), 7 deletions(-) (limited to 'users/Profpatsch/blog') 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 = "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"; + } + ]; + # 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 '' + + ''; + + notes-index = runExeclineStdout "notes-index" { stdin = depot.users.Profpatsch.netencode.gen.dwim notesFullRoute; } [ "withstdinas" "-in" "TEMPLATE_DATA" @@ -70,7 +115,7 @@ let bins.printf '' '' @@ -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 '' +
+ ${scope o (o: '' +
${esc o.name}
+
${html o.description}
+ '')} +
+ ''; + + projects-index = runExeclineStdout "projects-index" { + stdin = depot.users.Profpatsch.netencode.gen.dwim projects; + } [ + "withstdinas" "-in" "TEMPLATE_DATA" + "pipeline" [ + bins.printf '' +
+ {{#.}} +
{{name}}
+
{{{description}}}
+ {{/.}} +
+ '' + ] + 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 ; -- cgit 1.4.1