From d8d0b178234fc6ca2903af00d0c78d5931e27e3f Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 16 Jun 2023 02:18:18 +0300 Subject: refactor(tazjin/homepage): long overdue entry list rework The entry list is now much more condensed. It's maybe a little *too* condensed, but already closer to what I'm looking for. Note: A new "note" post type has snuck in and can now be used for random musings or comments on previous entries. Notes do not show up in the Atom feed. Change-Id: I920c0c7650937474b8a5f30cba78416554d523ce Reviewed-on: https://cl.tvl.fyi/c/depot/+/8806 Reviewed-by: tazjin Autosubmit: tazjin Tested-by: BuildkiteCI --- users/tazjin/homepage/default.nix | 55 ++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 18 deletions(-) (limited to 'users/tazjin/homepage/default.nix') diff --git a/users/tazjin/homepage/default.nix b/users/tazjin/homepage/default.nix index 15f4d787c0..b46f9d4917 100644 --- a/users/tazjin/homepage/default.nix +++ b/users/tazjin/homepage/default.nix @@ -15,13 +15,18 @@ let inherit (pkgs) writeFile runCommand; # The different types of entries on the homepage. - entryClass = enum "entryClass" [ "blog" "project" "misc" ]; + entryClass = enum "entryClass" [ + "blog" + "project" + "note" + "misc" + ]; # The definition of a single entry. entry = struct "entry" { class = entryClass; - title = string; - url = string; + title = option string; + url = option string; date = int; # epoch description = option string; }; @@ -33,28 +38,42 @@ let title = post.title; url = "/blog/${post.key}"; date = post.date; + description = post.description or "Blog post from ${formatDate post.date}"; }); formatDate = defun [ int string ] (date: readFile (runCommand "date" { } '' - date --date='@${toString date}' '+%Y-%m-%d' > $out + date --date='@${toString date}' '+%Y-%m-%d' | tr -d '\n' > $out '')); - formatEntryDate = defun [ entry string ] (entry: entryClass.match entry.class { - blog = "Blog post from ${formatDate entry.date}"; - project = "Project from ${formatDate entry.date}"; - misc = "Posted on ${formatDate entry.date}"; - }); + entryUrl = defun [ entry string ] (entry: + if entry.class == "note" + then "#${toString entry.date}" + else entry.url + ); + + hasDescription = defun [ entry bool ] (entry: + ((entry ? description) && (entry.description != null)) + ); + + entryTitle = defun [ entry string ] (entry: + let + optionalColon = lib.optionalString (hasDescription entry) ":"; + titleText = + if (!(entry ? title) && (entry.class == "note")) + then "[${formatDate entry.date}]" + else lib.optionalString (entry ? title) ((escape entry.title) + optionalColon); + in + lib.optionalString (titleText != "") + ''${titleText}'' + ); entryToDiv = defun [ entry string ] (entry: '' - -
-

${escape entry.title}

- ${ - lib.optionalString ((entry ? description) && (entry.description != null)) - "

${escape entry.description}

" - } - -
+
+ ${entryTitle entry} + ${ + lib.optionalString (hasDescription entry) + "${escape entry.description}" + } ''); -- cgit 1.4.1