2018-11-20 21:51:39 +01:00
|
|
|
<!-- Miscelaneous render related template parts we use multiple times -->
|
2020-08-19 15:28:44 +02:00
|
|
|
{{define "collection-meta"}}
|
|
|
|
{{if .Monetization -}}
|
2021-06-07 21:52:24 +02:00
|
|
|
<meta name="monetization" content="{{.DisplayMonetization}}" />
|
2020-08-19 15:28:44 +02:00
|
|
|
{{- end}}
|
|
|
|
{{end}}
|
|
|
|
|
2018-11-20 21:51:39 +01:00
|
|
|
{{define "highlighting"}}
|
2018-11-23 18:12:47 +01:00
|
|
|
<script>
|
|
|
|
// TODO: this feels more like a mutation observer
|
|
|
|
addEventListener('DOMContentLoaded', function () {
|
2018-12-07 22:37:14 +01:00
|
|
|
var hlbaseUri = "/js/";
|
2018-11-29 16:25:53 +01:00
|
|
|
var lb = document.querySelectorAll("code[class^='language-']");
|
|
|
|
|
|
|
|
|
2019-06-25 20:17:30 +02:00
|
|
|
// Custom aliasmap
|
|
|
|
var aliasmap = {
|
|
|
|
"elisp" : "lisp",
|
|
|
|
"emacs-lisp" : "lisp",
|
|
|
|
"c" : "cpp",
|
|
|
|
"cc" : "cpp",
|
|
|
|
"h" : "cpp",
|
|
|
|
"c++" : "cpp",
|
|
|
|
"h++" : "cpp",
|
|
|
|
"hpp" : "cpp",
|
|
|
|
"hh" : "cpp",
|
|
|
|
"hxx" : "cpp",
|
|
|
|
"cxx" : "cpp",
|
2020-02-26 22:12:06 +01:00
|
|
|
"sh" : "bash",
|
|
|
|
"js" : "javascript",
|
|
|
|
"jsx" : "javascript",
|
|
|
|
"html" : "xml"
|
2019-06-25 20:17:30 +02:00
|
|
|
};
|
2020-02-26 22:12:06 +01:00
|
|
|
|
2018-11-29 16:25:53 +01:00
|
|
|
// Given a set of nodes, run highlighting on them
|
|
|
|
function highlight(nodes) {
|
|
|
|
for (i=0; i < nodes.length; i++) {
|
|
|
|
hljs.highlightBlock(nodes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a array of URIs, load them in order
|
|
|
|
function loadLanguages(uris, callback) {
|
|
|
|
uris.forEach(function(uri) {
|
2018-12-03 18:18:04 +01:00
|
|
|
var sc = document.createElement('script');
|
|
|
|
sc.src = uri;
|
|
|
|
sc.async = false; // critical?
|
2019-06-25 20:17:30 +02:00
|
|
|
// Set callback on last script
|
2018-12-03 18:18:04 +01:00
|
|
|
if (uris.indexOf(uri) == uris.length-1) {
|
2019-03-05 14:36:40 +01:00
|
|
|
// Set callback regardless
|
|
|
|
// so we're sure it will run if last element had error
|
|
|
|
// (we only know after loading, so we've had load time already)
|
|
|
|
sc.onload = callback; sc.onerror = callback;
|
2018-12-03 18:18:04 +01:00
|
|
|
}
|
|
|
|
document.head.appendChild(sc);
|
2018-11-29 16:25:53 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't have to do anything if there are no language blocks
|
|
|
|
if (lb.length > 0) {
|
|
|
|
// We have blocks to be highlighted, so we load css
|
2018-11-23 18:12:47 +01:00
|
|
|
var st = document.createElement('link');
|
|
|
|
st.rel = "stylesheet";
|
2018-12-07 22:37:14 +01:00
|
|
|
st.href = "/css/lib/atom-one-light.min.css";
|
2018-11-29 16:25:53 +01:00
|
|
|
document.head.appendChild(st);
|
2018-11-22 14:31:25 +01:00
|
|
|
|
2018-11-29 16:25:53 +01:00
|
|
|
// Construct set of files to load, in order
|
|
|
|
var jss = [hlbaseUri + "highlight.min.js"];
|
|
|
|
// Check what we need to load
|
|
|
|
for (i=0; i < lb.length; i++) {
|
2021-01-24 02:24:12 +01:00
|
|
|
lang = lb[i].className.replace('language-','').toLowerCase();
|
2019-06-25 20:17:30 +02:00
|
|
|
// Support the aliases specified above
|
|
|
|
if (aliasmap[lang]) lang = aliasmap[lang];
|
2018-12-07 22:37:14 +01:00
|
|
|
lurl = hlbaseUri + "highlightjs/" + lang + ".min.js";
|
2019-06-27 17:13:20 +02:00
|
|
|
if (!jss.includes(lurl)) {
|
2018-12-03 18:18:04 +01:00
|
|
|
jss.push(lurl);
|
|
|
|
}
|
2018-11-23 18:12:47 +01:00
|
|
|
}
|
2023-03-05 08:23:24 +01:00
|
|
|
// Load files in order, highlight on last load
|
2018-11-29 16:25:53 +01:00
|
|
|
loadLanguages(jss, () => {highlight(lb)});
|
2018-11-23 18:12:47 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2018-11-20 21:51:39 +01:00
|
|
|
{{end}}
|
2018-11-20 22:01:25 +01:00
|
|
|
|
|
|
|
<!-- Include mathjax configuration -->
|
|
|
|
{{define "mathjax"}}
|
2019-09-11 23:04:13 +02:00
|
|
|
<script>
|
|
|
|
MathJax = {
|
|
|
|
tex: {
|
|
|
|
inlineMath: [
|
|
|
|
["\\(", "\\)"],
|
|
|
|
['$', '$'],
|
|
|
|
],
|
|
|
|
displayMath: [
|
|
|
|
['$$', '$$'],
|
|
|
|
['\\[', '\\]'],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
2018-11-20 22:01:25 +01:00
|
|
|
</script>
|
2019-09-12 19:19:08 +02:00
|
|
|
<script type="text/javascript" id="MathJax-script" src="/js/mathjax/tex-svg-full.js" async>
|
2018-11-20 22:01:25 +01:00
|
|
|
</script>
|
|
|
|
{{end}}
|