-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.sh
executable file
·109 lines (86 loc) · 3.04 KB
/
process.sh
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
manualContent="$manual/share/doc/nixos"
docset="$out/share/${docsetName}.docset"
contents="$docset/Contents"
function sql {
sqlite3 "$contents/Resources/docSet.dsidx" "$1"
}
function setupSchema {
sql "CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);"
sql "CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);"
}
function index {
local name="$1"
local type="$2"
local path="$3"
sql "INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ('$name', '$type', '$path');"
}
function scaffold {
echo "Scaffolding"
mkdir -p "$contents/Resources/Documents/options/"
mustache "$env" "$src/Info.tpl.plist" > "$contents/Info.plist"
mustache "$env" "$src/meta.tpl.json" > "$docset/meta.json"
cp "$src/nixos-logo.png" "$docset/icon.png"
setupSchema
}
function copyManual {
echo "Copying manual"
cp -r "$manualContent/." "$contents/Resources/Documents/"
}
function mkOptionSlug {
local name="$1"
echo "opt-$(echo "$name" | sed 's/[<>* ]/_/g')"
}
function indexOption {
local name="$1"
echo "Option '$name': indexing"
local slug="$(mkOptionSlug "$name")"
index "$name" "Option" "options/${slug}.html#${slug}"
}
function dropNewlines {
sed -z 's/\n/ /g'
}
function escapeQuotes {
sed 's/"/\\"/g'
}
function wrapHTML {
sed 's-^-<?xml version="1.0"?><b xmlns:xlink="https://www.w3.org/1999/xlink">-;s-$-</b>-'
}
function replaceLinks {
wrapHTML | xsltproc "$src/links.xslt" -
}
function generateOptionPage {
local name="$1"
echo "Option '$name': generating webpage"
slug=$(mkOptionSlug "$name")
optionType="$( readOptionAttribute "$name" "type" )"
optionDescription="$(readOptionAttribute "$name" "description" | dropNewlines | replaceLinks | escapeQuotes )"
optionExample="$( readOptionAttribute "$name" "example" | dropNewlines | escapeQuotes )"
optionDefault="$( readOptionAttribute "$name" "default" | dropNewlines | escapeQuotes )"
# FIXME this might be properly working
optionSource="$( readOptionAttribute "$name" "declarations[0]" )"
echo "{ \"name\": \"$name\", \"slug\": \"$slug\", \"type\": \"$optionType\", \"description\": \"$optionDescription\", \"default\": \"$optionDefault\", \"source\": \"$optionSource\", \"example\": \"$optionExample\" }" > "${slug}.json"
mustache "${slug}.json" "$src/option.tpl.html" > "$contents/Resources/Documents/options/${slug}.html"
}
function readOptionAttribute {
local name="$1"
local attribute="$2"
jq ".\"${name}\".${attribute}" "$options/share/doc/nixos/options.json" -r
}
function processOption {
local name="$1"
generateOptionPage "$name"
indexOption "$name"
}
function listOptions {
jq keys[] $options/share/doc/nixos/options.json -r | head -$maxOptionsToIndex
}
function processOptions {
listOptions | while read opt; do processOption "$opt"; done
}
function archive {
tar -cvzf "$out/share/${docsetName}.tgz" "$docset"
}
scaffold
copyManual
processOptions
archive