-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate
executable file
·78 lines (71 loc) · 2.64 KB
/
generate
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
#!/usr/bin/env bash
CWD="$(realpath .)"
function build_docs() {
REV="$1"
URL="$1"
if [[ ! "$URL" =~ ^https?:\/\/ ]]; then
URL="https://github.com/NixOS/nixpkgs/archive/$URL.tar.gz"
fi
NIXPKGS_HASH=`nix-prefetch-url "$URL" --type sha256 --unpack --name "nixpkgs-$1" | tail -n 1`
if [[ "$REV" != "$URL" ]]; then
REV="$NIXPKGS_HASH"
fi
nix-build --argstr tarball_url "$URL" --argstr tarball_sha256 "$NIXPKGS_HASH" --argstr rev "$REV"
}
function norm_branch() {
echo "$branch" | sed 's;[\/:];-;g'
}
function build_branch() {
echo "$(build_docs "$1")"
}
function build_branches() {
rm -rf target
mkdir -p target
for branch in "$@"; do
norm_branch="$(norm_branch "$branch")"
OUT_LINK="$(build_branch "$branch")" && {
pushd "$OUT_LINK" > /dev/null
mkdir "$CWD/target/$norm_branch"
find . -type d | while read line; do
mkdir -p "$CWD/target/$norm_branch/$line"
done
find . -type l | while read line; do
cp -Lr "$line" "$CWD/target/$norm_branch/$line" --preserve=timestamps
done
popd > /dev/null
}
done
}
function generate_html() {
{
echo '<html>'
echo '<head>'
echo '<meta charset="utf-8">'
echo '<title>Available built documentation</title>'
echo '<style>'
echo ' '
echo '</style>'
echo '</head>'
echo '<body>'
echo '<h1>nixpkgs/NixOS documentation</h1>'
echo "<p>Generated at $(date)</p>"
for branch in "$@"; do
norm_branch="$(norm_branch "$branch")"
echo "<section id="branch-$norm_branch">"
echo "<h1><b>Branch:</b> $branch</h1>"
echo '<ul>'
echo "<li><a href=\"$norm_branch/nixpkgs/manual.html\">nixpkgs manual</a></li>"
echo "<li><a href=\"$norm_branch/nixpkgs/nixpkgs-manual.epub\">nixpkgs manual (epub)</a></li>"
echo "<li><a href=\"$norm_branch/nixos/index.html\">NixOS documentation</a></li>"
echo "<li><a href=\"$norm_branch/nixos/options.html\">NixOS options</a></li>"
echo "<li><a href=\"$norm_branch/nixos/release-notes.html\">NixOS release notes</a></li>"
echo "<li><a href=\"$norm_branch/nixpkgs.docset.tgz\">Zeal/Dash docset</a></li>"
echo '</ul>'
echo '</section>'
done
echo '</body>'
echo '</html>'
} > target/index.html
}
build_branches "$@"
generate_html "$@"