diff options
Diffstat (limited to 'users/tazjin/homepage/default.nix')
-rw-r--r-- | users/tazjin/homepage/default.nix | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/users/tazjin/homepage/default.nix b/users/tazjin/homepage/default.nix index 8f53eba67e..b46f9d4917 100644 --- a/users/tazjin/homepage/default.nix +++ b/users/tazjin/homepage/default.nix @@ -5,60 +5,79 @@ # elements for things such as blog posts and projects. # # Content for the blog is in //users/tazjin/blog instead of here. -{ depot, lib, ... }@args: +{ depot, lib, pkgs, ... }@args: with depot; with nix.yants; let inherit (builtins) readFile replaceStrings sort; - inherit (third_party) writeFile runCommandNoCC; + 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; }; escape = replaceStrings [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ]; - postToEntry = defun [ users.tazjin.blog.post entry ] (post: { + postToEntry = defun [ web.blog.post entry ] (post: { class = "blog"; 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 (runCommandNoCC "date" {} '' - date --date='@${toString date}' '+%Y-%m-%d' > $out + formatDate = defun [ int string ] (date: readFile (runCommand "date" { } '' + 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 != "") + ''<span class="entry-title ${entry.class}">${titleText}</span>'' + ); entryToDiv = defun [ entry string ] (entry: '' - <a href="${entry.url}" class="entry ${entry.class}"> - <div> - <p class="entry-title">${escape entry.title}</p> - ${ - lib.optionalString ((entry ? description) && (entry.description != null)) - "<p class=\"entry-description\">${escape entry.description}</p>" - } - <p class="entry-date">${formatEntryDate entry}</p> - </div> + <a href="${entryUrl entry}" id="${toString entry.date}" class="entry"> + ${entryTitle entry} + ${ + lib.optionalString (hasDescription entry) + "<span class=\"entry-description\">${escape entry.description}</span>" + } </a> ''); - index = entries: third_party.writeText "index.html" (lib.concatStrings ( + index = entries: pkgs.writeText "index.html" (lib.concatStrings ( [ (builtins.readFile ./header.html) ] ++ (map entryToDiv (sort (a: b: a.date > b.date) entries)) ++ [ (builtins.readFile ./footer.html) ] @@ -67,9 +86,12 @@ let pageEntries = import ./entries.nix; homepage = index ((map postToEntry users.tazjin.blog.posts) ++ pageEntries); atomFeed = import ./feed.nix (args // { inherit entry pageEntries; }); -in runCommandNoCC "website" {} '' +in +runCommand "website" { } '' mkdir $out cp ${homepage} $out/index.html cp ${atomFeed} $out/feed.atom - cp -r ${./static} $out/static + mkdir $out/static + cp -r ${depot.web.static}/* $out/static + cp -rf ${./static}/* $out/static '' |