-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBuildSidebarJS.js
More file actions
54 lines (44 loc) · 1.4 KB
/
BuildSidebarJS.js
File metadata and controls
54 lines (44 loc) · 1.4 KB
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
const fs = require("fs");
const { exec } = require("child_process");
const { promisify } = require("util");
const execPromise = promisify(exec);
function getMathJaxSetup() {
return `
window.MathJax = {
loader: { load: ['tex-svg', '[tex]/color'] },
tex: { packages: { '[+]': ['color'] } },
svg: {
fontCache: 'none'
},
startup: {
typeset: false // Prevent auto-typesetting
},
options: {
enableAssistiveMml: false
}
};
`;
}
function wrapJS(sidebarJS, includeMathJax) {
const mathJaxSetup = includeMathJax ? getMathJaxSetup() : "";
const mathJaxScript = includeMathJax
? '\n<script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>'
: "";
return `<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
${mathJaxSetup}
${sidebarJS}</script>${mathJaxScript}`;
}
async function compileTS() {
await execPromise("npx tsc --preserveConstEnums Sidebar.ts -t es2020 --lib es2020,dom --skipLibCheck");
}
async function buildSidebarJS() {
await compileTS();
const sidebarJS = fs.readFileSync("Sidebar.js", "utf8");
const sidebarHTML = fs.readFileSync("Sidebar.html", "utf8");
const includeMathJax = sidebarHTML.includes("data-mathjax-enabled");
const wrapped = wrapJS(sidebarJS, includeMathJax);
// write out
fs.writeFileSync("SidebarJS.html", wrapped);
}
buildSidebarJS();