Last active
August 10, 2022 08:46
-
-
Save shabbyrobe/c0131998cbfa43f0bc01a376c23c0ced to your computer and use it in GitHub Desktop.
Disgusting docset builder for mithril.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# As soon as I don't have to spend two hours debugging dependency failures from the | |
# master checkout of mithril.js, I will work this into their build process and submit | |
# a PR. | |
set -o errexit -o nounset -o pipefail | |
if [[ ! -d "build" ]]; then | |
mkdir build | |
fi | |
pushd build | |
mkdir -p Mithril.docset/Contents/Resources/Documents/ | |
# dependencies | |
if [[ ! -d "node_modules/highlight.js" ]]; then | |
npm install highlight.js | |
fi | |
if [[ ! -d "node_modules/marked" ]]; then | |
npm install marked | |
fi | |
if [[ ! -d "mithril.js" ]]; then | |
git clone https://github.com/lhorie/mithril.js.git | |
fi | |
curl -O http://mithril.js.org/style.css | |
# markdown | |
rm -f Mithril.docset/Contents/Resources/Documents/* || true | |
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(contents) + tplLower); | |
}); | |
EOS | |
echo "$js" | node | |
# logo | |
echo "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACYVBMVEVGokZGo0ZHo0dIo0hJpElKpEpLpUtMpUxMpkxNpk1Opk5Op05Pp09Qp1BQqFBRqFFSqFJRqVFSqVJTqVNUqVRUqlRVqlVWqlZXqldWq1ZXq1dYq1hYrFhZrFlarFparVpbrVtcr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kp8FVhAnNhNkgoPyMiCnjlejlaUcLC5ryqsM1uOmsBCkIFWs+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 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 | |
threw up a repo in the meantime and made some changes, though minor
Hahahah thanks @shmup, I forgot this even existed, haven't used mithril for years (though I was always very fond of it). Glad this helped you out, I'm very happy to see this turned into a first class project.
damn u been debugging dep failures forever π
Yes, I think on some level this is definitely still true, in one way or another π
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
damn u been debugging dep failures forever π
changed required on line 85:
thanks for having what may be the only docset generator for mithril.js!