From cce872e3977d3f7e2001a76310d98f6fa80d7243 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 8 Feb 2020 22:21:06 +0000 Subject: feat(web/homepage): Add Nix code to assemble the index page 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. --- web/homepage/default.nix | 51 +++++++++++++++++++++++++++++++++++++++++++++++- web/homepage/entries.nix | 1 + web/homepage/footer.html | 2 ++ web/homepage/header.html | 33 +++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 web/homepage/entries.nix create mode 100644 web/homepage/footer.html create mode 100644 web/homepage/header.html (limited to 'web') 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 [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ]; + + 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: '' +
+

${escape entry.title}

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

${escape entry.description}

" + } +
+ ''); + + 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; } diff --git a/web/homepage/entries.nix b/web/homepage/entries.nix new file mode 100644 index 000000000000..fe51488c7066 --- /dev/null +++ b/web/homepage/entries.nix @@ -0,0 +1 @@ +[] diff --git a/web/homepage/footer.html b/web/homepage/footer.html new file mode 100644 index 000000000000..2f17135066e8 --- /dev/null +++ b/web/homepage/footer.html @@ -0,0 +1,2 @@ + + diff --git a/web/homepage/header.html b/web/homepage/header.html new file mode 100644 index 000000000000..832306fae3a4 --- /dev/null +++ b/web/homepage/header.html @@ -0,0 +1,33 @@ + + + + + + + tazjin's interblag + + +
+

+ tazjin's interblag +

+
+
+
+

Hello, illuminated visitor.

+

+ I'm tazjin. Usually you can find + me programming computers + using tools such as Nix + and Emacs, + cuddling people I love + or posting nonsense on the + internet. +

+

+ Below you can find a collection of my projects and blog posts. + If you'd like to get in touch about anything, send me a mail at + mail@[this domain] or ping me on IRC or Twitter. +

+
+
-- cgit 1.4.1