blob: 1e2c4c6f8bc00b73506f6bbbe99b86509e565c6f (
plain)
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
|
{
stdenvNoCC,
# Packages
line-awesome,
line-awesome-css,
uncss,
yuicompressor,
imagemagick,
nix,
minify,
# Source files
nixpkgsSrc,
src,
data,
}: let
compress = "${yuicompressor}/bin/yuicompressor";
clean = "${uncss}/bin/uncss";
compressJPEG = size: image: ''
${imagemagick}/bin/magick ${image} \
-sampling-factor 4:2:0 \
-strip \
-quality 85 \
-interlace JPEG \
-colorspace RGB \
-resize ${size}x${size} \
-colorspace sRGB \
${image}.${size}
'';
mkPushDir = dir: ''mkdir -p ${dir} && pushd "$_"'';
nixEvalExpr = "${nix}/bin/nix --extra-experimental-features nix-command --extra-experimental-features flakes eval --impure --raw --show-trace --expr";
make = "import $src/make.nix {pkgs = import ${nixpkgsSrc} {}; dataSrc = $src/data;}";
in
stdenvNoCC.mkDerivation {
name = "webpage";
requiredSystemFeatures = ["recursive-nix"];
subsrcs = [src data];
src = "webpage-src";
unpackPhase = ''
read -ra srcs <<< "$subsrcs"
mkdir $src
ln -s ''${srcs[0]}/* $src/
ln -s ''${srcs[1]} $src/data
ls $src
'';
installPhase = ''
# set -o xtrace
pushd $src
src=$(pwd)
popd
${mkPushDir "$out"} # $out/
# build HTML
${nixEvalExpr} "
${make} $src/html {}
" > index.html
${minify}/bin/minify index.html --output index.html
# copy static files
cp -r $src/static/ .
ln -s static/robots.txt
chmod 777 static
pushd static # $out/static/
cp -r ${data}/files .
chmod 777 files
pushd files # $out/static/files/
${compressJPEG "128" "avatar.jpg"}
${compressJPEG "256" "avatar.jpg"}
${compressJPEG "512" "avatar.jpg"}
popd # $out/static/
# build and compress CSS
${mkPushDir "css"} # $out/static/css/
${nixEvalExpr} "
${make} $src/css/classless.nix {
big-first-letter = true;
details-cards = true;
grid = true;
hr = false;
navbar = true;
tables = false;
tooltip-citations = true;
printing = true;
tabs = true;
}
" > classless.css
${clean} $out/index.html --stylesheets file://$(pwd)/classless.css \
| ${compress} --type css >classless.min.css
rm classless.css
${mkPushDir "fonts/line-awesome"} # $out/static/css/fonts/lineawesome
ln -s ${line-awesome}/share/fonts/woff2 webfonts
${clean} $out/index.html --stylesheets file://${line-awesome-css} \
| ${compress} --type css >line-awesome.min.css
popd # $out/static
popd # $out/
popd #
'';
}
|