-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-mithril-docset.sh
executable file
·130 lines (106 loc) · 6.21 KB
/
build-mithril-docset.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
if [[ ! -d "build" ]]; then
mkdir build
fi
pushd build
# dependencies
if ! [ "$(command -v npm)" ]; then
echo "gonna need npm/node" && exit 0
fi
if ! [ "$(command -v sqlite3)" ]; then
echo "gonna need sqlite3" && exit 0
fi
if [[ ! -d "mithril.js" ]]; then
git clone https://github.com/lhorie/mithril.js.git
fi
curl -ORs http://mithril.js.org/style.css
mkdir -p Mithril.docset/Contents/Resources/Documents/
cp ../package.json .
npm install
# markdown
rm -f Mithril.docset/Contents/Resources/Documents/*
read -r -d '' js <<EOS || true
'use strict';
const marked = require('marked');
const fs = require('fs');
const path = require('path');
let css = fs.readFileSync("style.css").toString("utf8");
// pasted in from highlight.js bundle download, googlecode style
css += "\n/* Google Code style (c) Aahan Krish <[email protected]> */ .hljs { display: block; overflow-x: auto; padding: 0.5em; background: white; color: black; } .hljs-comment, .hljs-quote { color: #800; } .hljs-keyword, .hljs-selector-tag, .hljs-section, .hljs-title, .hljs-name { color: #008; } .hljs-variable, .hljs-template-variable { color: #660; } .hljs-string, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-regexp { color: #080; } .hljs-literal, .hljs-symbol, .hljs-bullet, .hljs-meta, .hljs-number, .hljs-link { color: #066; } .hljs-title, .hljs-doctag, .hljs-type, .hljs-attr, .hljs-built_in, .hljs-builtin-name, .hljs-params { color: #606; } .hljs-attribute, .hljs-subst { color: #000; } .hljs-formula { background-color: #eee; font-style: italic; } .hljs-selector-id, .hljs-selector-class { color: #9B703F } .hljs-addition { background-color: #baeeba; } .hljs-deletion { background-color: #ffc8bd; } .hljs-doctag, .hljs-strong { font-weight: bold; } .hljs-emphasis { font-style: italic; }\n";
// some style override hacks to fix zeal misbehaving with the downloaded mithril
// stylesheet. this may not play nice with Dash or if the mithril style gets
// updated.
css += "\n" +
"html { font-size: 1.2em; font-family: Helvetica, Arial, Sans-Serif; }\n" +
".content { padding: 15px; }\n";
let outPath = __dirname + "/Mithril.docset/Contents/Resources/Documents/";
let tplUpper = "<!doctype html>\n<html>\n<head>\n" +
"<style type=\"text/css\">\n" + css + "</style>" +
"</head><body><main><section class='content'>";
let tplLower = "</body></html>";
marked.setOptions({
highlight: function (code) { return require('highlight.js').highlightAuto(code).value; }
});
let d = "mithril.js/docs/";
let tplFiles = fs.readdirSync(d);
let tplContents = {};
for (let i = 0; i < tplFiles.length; i++) {
let f = tplFiles[i];
let ff = d + f;
if (!fs.lstatSync(ff).isFile()) {
continue;
}
let p = path.parse(f);
tplContents[p.name] = fs.readFileSync(ff).toString('utf8');
}
Object.keys(tplContents).forEach((k) => {
console.log(k);
let contents = tplContents[k];
let o = contents;
Object.keys(tplContents).forEach((l) => {
// the open bracket helps make sure we are (probably) only stuffing around
// with the markdown links and nothing else.
contents = contents.split("(" + l + ".md").join("(" + l + ".html");
});
fs.writeFileSync(outPath + "/" + k + '.html', tplUpper + marked.parse(contents) + tplLower);
});
EOS
echo "$js" | node
# logo
echo "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACYVBMVEVGokZGo0ZHo0dIo0hJpElKpEpLpUtMpUxMpkxNpk1Opk5Op05Pp09Qp1BQqFBRqFFSqFJRqVFSqVJTqVNUqVRUqlRVqlVWqlZXqldWq1ZXq1dYq1hYrFhZrFlarFparVpbrVtcrVx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8FVhAnNhNkgoPyMiCnjlejlaUcLC5ryqsM1uOmsBCkIFWs+dSpdZzqO9Yq2IOEFzFmT+IxBjL2aRhuASlYwhZ66lSEePWpA06iILO8+eediuGrPnWqTcoPElA+7NO3G6oAGRUi4UdPdYu7HDo1X9b1yAkr9hUQBevl+KuEEkCmW7BXLtOXmghkaRisimRLgUVWC68IZyeIsd9RQF24HcQKljHlCjwCj+4p/KJKWTNWz87RFhMTC+tZuahRU1Qg4CRSgunkUWdnZGBk1YnMsBJgZGBgFpcsR0lRC0T8FjcW189cf/LUrqVtJRW9ikZbURRsM1E4hJxUp8t4HEdNtLFiBUjyJwO5u9BS9R5+qeUIBflc7hjJfpYI39SjEOb+dA7jg5j5ol2MP6Rpzf5dCwtt2ExXYctZG534xaVlZKTEhJOP4ch6M+I9HF18c9fgyZvH9h8iNfMCAEmLaj5hVA4RAAAAAElFTkSuQmCC" |
base64 -d >Mithril.docset/icon.png
# plist
read -r -d '' plist <<EOS || true
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>mithril</string>
<key>CFBundleName</key>
<string>Mithril</string>
<key>DocSetPlatformFamily</key>
<string>mithril</string>
<key>isDashDocset</key>
<true/>
<key>dashIndexFilePath</key>
<string>mithril.html</string>
</dict>
</plist>
EOS
echo "$plist" >Mithril.docset/Contents/Info.plist
# index
index_path="Mithril.docset/Contents/Resources/docSet.dsidx"
rm -f "$index_path"
echo '
CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);
CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);
' | sqlite3 "$index_path"
find mithril.js/docs -maxdepth 1 -type f -name '*.md' -printf '%f\n' | while read -r line; do
type="Guide"
if [[ "$line" =~ ^mithril\. ]]; then
type="Module"
fi
sqlite3 "$index_path" "INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES('${line%%.md}', '$type', '${line%%.md}.html')"
done