-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsite.nix
189 lines (151 loc) · 6.28 KB
/
site.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*-----------------------------------------------------------------------------
Init
Initialization of Styx, should not be edited
-----------------------------------------------------------------------------*/
{ pkgs ? import <nixpkgs> {}
, extraConf ? {}
}:
rec {
styx-themes = import pkgs.styx.themes;
styx = import pkgs.styx {
# Used packages
inherit pkgs;
# Used configuration
config = [
./conf.nix
extraConf
];
# Loaded themes
themes = [
styx-themes.generic-templates
./themes/styx-site
];
# Environment propagated to templates
env = { inherit data pages; };
};
# Propagating initialized data
inherit (styx.themes) conf files templates env lib;
/*-----------------------------------------------------------------------------
Data
This section declares the data used by the site
-----------------------------------------------------------------------------*/
data = with lib; {
posts = sortBy "date" "dsc" (loadDir { dir = ./posts; inherit env; });
doc = lib.mapAttrs (v: _: mkDocPath v) versions;
navbar = [
pages.news
{ title = "Documentation"; path = "/documentation/index.html"; }
pages.themesList
{ title = "GitHub ${templates.icon.font-awesome "github"}"; url = "https://github.com/styx-static/styx/"; }
(pages.feed // { navbarTitle = (templates.icon.font-awesome "rss-square") + ''<span class="sr-only">RSS</span>''; })
];
# themes meta information to generate the themes list
themes = with lib;
let
data = map (t: lib.themes.loadData { inherit lib; theme = t; }) (attrValues styx-themes);
# adding screenshot data
data' = map (t:
let
preMeta = { meta.name = t.meta.id; };
postMeta = optionalAttrs (t.meta ? screenshot) {
meta = {
screenshotPath = "/imgs/themes/${t.meta.id}.png";
thumbnailPath = "/imgs/themes/${t.meta.id}-thumb.png";
};
};
in lib.utils.merge [ preMeta t postMeta ]
) data;
in data';
};
/*-----------------------------------------------------------------------------
Pages
This section declares the pages that will be generated
-----------------------------------------------------------------------------*/
pages = rec {
index = {
title = "Home";
path = "/index.html";
template = templates.index;
};
news = {
title = "News";
path = "/news.html";
template = templates.news;
};
feed = {
path = "/feed.xml";
template = templates.feed.atom;
items = lib.take 10 pages.posts.list;
layout = lib.id;
};
posts = lib.mkPageList {
data = data.posts;
pathPrefix = "/posts/";
template = templates.post.full;
breadcrumbs = [ index news ];
};
themesList = {
title = "Themes";
path = "/themes.html";
template = templates.theme-list;
};
themes = lib.map (t:
t // {
path = "/themes/${t.id}.html";
template = templates.theme.full;
title = t.meta.name;
breadcrumbs = [ index themesList ];
}
) data.themes;
};
/*-----------------------------------------------------------------------------
Site rendering
-----------------------------------------------------------------------------*/
name = "Styx Official Site";
pageList = lib.pagesToList {
inherit pages;
default.layout = templates.layout;
};
# fetch the versions to create the documentations
fetchStyx = version: fetchTarball "https://github.com/styx-static/styx/archive/${version}.tar.gz";
fetchNixpkgs = rev: fetchTarball "https://github.com/nixos/nixpkgs/archive/${rev}.tar.gz";
# list of versions to generate documentation from
versions = {
"v0.7.5" = import (fetchStyx "v0.7.5") { pkgs = import (fetchNixpkgs "a977252b40f766dec5bd997c2b81a0833ca7c962") {};};
"v0.7.2" = import (fetchStyx "v0.7.2") { pkgs = import (fetchNixpkgs "2c1838ab99b086dccad930e8dcc504b867149a0c") {};};
"v0.7.0" = import (fetchStyx "v0.7.0") { pkgs = import (fetchNixpkgs "2c1838ab99b086dccad930e8dcc504b867149a0c") {};};
"v0.6.0" = import (fetchStyx "v0.6.0") { pkgs = import (fetchNixpkgs "2c1838ab99b086dccad930e8dcc504b867149a0c") {};};
"v0.5.0" = import (fetchStyx "v0.5.0") { pkgs = import (fetchNixpkgs "2c1838ab99b086dccad930e8dcc504b867149a0c") {};};
"v0.4.0" = import (fetchStyx "v0.4.0") { pkgs = import (fetchNixpkgs "2c1838ab99b086dccad930e8dcc504b867149a0c") {};};
"v0.3.1" = import (fetchStyx "v0.3.1") { pkgs = import (fetchNixpkgs "2c1838ab99b086dccad930e8dcc504b867149a0c") {};};
"v0.3.0" = import (fetchStyx "v0.3.0") { pkgs = import (fetchNixpkgs "2c1838ab99b086dccad930e8dcc504b867149a0c") {};};
"v0.2.0" = import (fetchStyx "v0.2.0") { pkgs = import (fetchNixpkgs "2c1838ab99b086dccad930e8dcc504b867149a0c") {};};
"v0.1.0" = import (fetchStyx "v0.1.0") { pkgs = import (fetchNixpkgs "2c1838ab99b086dccad930e8dcc504b867149a0c") {};};
};
latestVersion = versions."${lib.last (lib.attrNames versions)}";
substitutions = {
siteUrl = conf.siteUrl;
};
mkDocPath = v: "/documentation/${v}/";
site = lib.mkSite {
inherit files pageList substitutions;
postGen = with lib; ''
# Themes screenshots
${mapTemplate (t:
optionalString (t.meta ? screenshotPath) ''
mkdir -p $(dirname "$out${t.meta.screenshotPath}")
${pkgs.imagemagick}/bin/convert "${t.meta.screenshot}" "$out${t.meta.screenshotPath}"
${pkgs.imagemagick}/bin/convert "${t.meta.screenshot}" -resize 720 -gravity north -extent 720x500 "$out${t.meta.thumbnailPath}"
''
) data.themes}
# Manuals
mkdir -p $out/documentation/
ls -la ${latestVersion}/share/doc/styx/*
cp -r ${latestVersion}/share/doc/styx/* $out/documentation/
${lib.concatStringsSep "\n" (mapAttrsToList (version: package: ''
mkdir -p $out/documentation/${version}/
cp -r ${package}/share/doc/styx/* $out/documentation/${version}/
'') versions)}
'';
};
}