blob: f6892576f5fe79ec7de9231646fe8290337bab15 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# Assembles the website index and configures an nginx instance to
# serve it.
#
# The website is made up of a simple header&footer and content
# elements for things such as blog posts and projects.
#
# Content for the blog is in //web/blog instead of here.
{ pkgs, lib, ... }:
with pkgs;
with nix.yants;
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: ''
<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;
}
|