-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
92 lines (73 loc) · 2.11 KB
/
default.nix
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{ pkgs ? import <nixpkgs> {}, templateOverrides ? (x: x), config }:
let
lib = pkgs.lib;
b = builtins;
utils = import ./nix/utils.nix { pkgs = pkgs; };
mkConfig = (import ./nix/config.nix { pkgs = pkgs; }).mkConfig;
conf = mkConfig config;
oldTmpl = import ./nix/templates.nix { pkgs = pkgs; config = conf; };
tmpl = oldTmpl // templateOverrides oldTmpl;
postsDir = conf.postsDir;
navPages = map utils.parseFile conf.navPages;
navPagesScript =
let
script = md: ''
cat << \EOF > $out/${md.fname}.html
${baseTmpl md.meta.title md.html}
EOF
'';
in
b.concatStringsSep "\n" (map script navPages);
baseTmpl = tmpl.base navPages;
posts = map utils.parseFile (utils.allFilepathsWithExtsIn postsDir [ "md" "nix" ]);
postsTable = baseTmpl "Posts" (tmpl.postsTable posts);
postPagesScript =
let
script = md: ''
cat << \EOF > $out/${tmpl.postUrl md}
${baseTmpl md.meta.title (tmpl.postPage md)}
EOF
'';
in
b.concatStringsSep "\n" (map script posts);
tags = utils.tagsMap posts;
mkTagPage = tag: mds:
baseTmpl ''Posts tagged "${tag}"'' (tmpl.postsList mds);
tagsList = baseTmpl "Tags" (tmpl.tagsList tags);
tagPages = lib.mapAttrs mkTagPage tags;
tagPagesScript =
let
script = tag: content: ''
cat << \EOF > $out/${tmpl.tagUrl tag}
${content}
EOF
'';
in
b.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs script tagPages));
buildInfo = "build-info.txt";
buildInfoScript = ''
rm -f $out/${buildInfo}
git -C ${conf.rootDir} log -1 --format="%H%n%cd" > $out/${buildInfo}
'';
in
pkgs.runCommand "site" { buildInputs = ( [ pkgs.git ] ++ conf.extraScript.inputs pkgs ); } ''
mkdir $out
# index
cat << \EOF > $out/index.html
${postsTable}
EOF
# posts
mkdir -p $out/posts
${postPagesScript}
# tags list
cat << \EOF > $out/tags.html
${tagsList}
EOF
# per-tag pages
mkdir -p $out/tags
${tagPagesScript}
# nav pages
${navPagesScript}
${if conf.buildInfo then buildInfoScript else ""}
${conf.extraScript.script}
''