about summary refs log tree commit diff
path: root/web/homepage/default.nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-02-08T22·21+0000
committerVincent Ambo <tazjin@google.com>2020-02-08T22·21+0000
commitcce872e3977d3f7e2001a76310d98f6fa80d7243 (patch)
tree4b7a4692842ffb6546114e51129dcd9d7c7db444 /web/homepage/default.nix
parent7935957938fb4bd73b557e42fa828b1470979777 (diff)
feat(web/homepage): Add Nix code to assemble the index page r/488
This is not yet fully functional, but going in the right direction.

Some concepts are introduced:

* There is a light theme (used for blog entry pages) and a dark
  theme (used for the homepage itself)
* Entries can be either blog posts, projects or miscellaneous things
  that I want to link people to (possibly with a comment)

It might be interesting to add pages that filter to specific types, or
some such, which should be relatively easy to do.

Note that the layouts of entries are not actually done yet.
Diffstat (limited to 'web/homepage/default.nix')
-rw-r--r--web/homepage/default.nix51
1 files changed, 50 insertions, 1 deletions
diff --git a/web/homepage/default.nix b/web/homepage/default.nix
index 94dfaf3dc6f1..f6892576f5fe 100644
--- a/web/homepage/default.nix
+++ b/web/homepage/default.nix
@@ -10,6 +10,55 @@
 with pkgs;
 with nix.yants;
 
-third_party.callPackage ./nginx.nix {
+let
+  inherit (builtins) readFile replaceStrings sort;
+  inherit (third_party) writeFile runCommandNoCC;
+
+  # The different types of entries on the homepage.
+  entryClass = enum "entryClass" [ "blog" "project" "misc" ];
+
+  # The definition of a single entry.
+  entry = struct "entry" {
+    class = entryClass;
+    title = string;
+    url = string;
+    date = int; # epoch
+    description = option string;
+  };
+
+  escape = replaceStrings [ "<" ">" "&" "'" ] [ "&lt;" "&gt;" "&amp;" "&#39;" ];
+
+  postToEntry = defun [ web.blog.post entry ] (post: {
+    class = "blog";
+    title = "Blog: " + post.title;
+    url = "/blog/${post.key}";
+    date = post.date;
+  });
+
+  # TODO(tazjin): add date formatting function
+  entryToDiv = defun [ entry string ] (entry: ''
+    <div class="entry ${entry.class}">
+      <p class="entry-title">${escape entry.title}</p>
+      ${
+        lib.optionalString ((entry ? description) && (entry.description != null))
+        "<p class=\"entry-description\">${escape entry.description}</p>"
+      }
+    </div>
+  '');
+
+  index = entries: third_party.writeText "index.html" (lib.concatStrings (
+    [ (builtins.readFile ./header.html) ]
+    ++ (map entryToDiv (sort (a: b: a.date < b.date) entries))
+    ++ [ (builtins.readFile ./footer.html) ]
+  ));
+
+  homepage = index ((map postToEntry web.blog.posts) ++ (import ./entries.nix));
+  website = runCommandNoCC "website" {} ''
+    mkdir $out
+    cp ${homepage} $out/index.html
+    cp -r ${./static} $out/static
+  '';
+in third_party.callPackage ./nginx.nix {
+  inherit website;
   blog = web.blog;
 }